Skip to content

Slack service API returns "1" and "0" for boolean properties.

Summary

Slack service API returns "1" and "0" for boolean properties notify_only_broken_pipelines and notify_only_default_branch, but should return true or false.

Steps to reproduce

  1. Export environment variables for convenience
     export GITLAB_URL="https://gitlab.com/api/v4"
     export GITLAB_TOKEN="put-token-here"
     
  2. Create a new project
     curl -sS -XPOST "$GITLAB_URL/projects" \
         -H "PRIVATE-TOKEN: $GITLAB_TOKEN" \
         -H "Content-Type: application/json" \
         -d '{"name": "example"}' | jq
     {
         "id": 7822153,
         "description": null,
         "name": "example",
         ...
     }
     
  3. Check Slack service
     curl -sS -XGET "$GITLAB_URL/projects/7822153/services/slack" \
         -H "PRIVATE-TOKEN: $GITLAB_TOKEN" | jq
     {
         "id": null,
         "title": "Slack notifications",
         "created_at": null,
         "updated_at": null,
         "active": false,
         "push_events": true,
         "issues_events": true,
         "confidential_issues_events": true,
         "merge_requests_events": true,
         "tag_push_events": true,
         "note_events": true,
         "confidential_note_events": true,
         "pipeline_events": true,
         "wiki_page_events": true,
         "job_events": true,
         "properties": {
             "notify_only_broken_pipelines": true,
             "notify_only_default_branch": true
         }
     }
     
  4. Turn off notification settings for Slack
     curl -sS -XPUT "$GITLAB_URL/projects/7822153/services/slack" \
         -H "Content-Type: application/json" \
         -H "PRIVATE-TOKEN: $GITLAB_TOKEN" \
         -d '{"webhook": "https://google.com", "notify_only_broken_pipelines": false, "notify_only_default_branch": false}' | jq
     {
         "id": 41006774,
         "title": "Slack notifications",
         "created_at": "2018-08-08T19:11:39.973Z",
         "updated_at": "2018-08-08T19:11:39.973Z",
         "active": true,
         "push_events": true,
         "issues_events": true,
         "confidential_issues_events": true,
         "merge_requests_events": true,
         "tag_push_events": true,
         "note_events": true,
         "confidential_note_events": true,
         "pipeline_events": true,
         "wiki_page_events": true,
         "job_events": true,
         "properties": {
             "webhook": "https://google.com",
             "notify_only_broken_pipelines": false,
             "notify_only_default_branch": false
         }
     }
     
  5. Disable Slack service
     curl -sS -XDELETE "$GITLAB_URL/projects/7822153/services/slack" \
         -H "PRIVATE-TOKEN: $GITLAB_TOKEN"
     
  6. Check Slack service again
     curl -sS -XGET "$GITLAB_URL/projects/7822153/services/slack" \
         -H "PRIVATE-TOKEN: $GITLAB_TOKEN" | jq
     {
         "id": 41006774,
         "title": "Slack notifications",
         "created_at": "2018-08-08T19:11:39.973Z",
         "updated_at": "2018-08-08T19:13:56.190Z",
         "active": false,
         "push_events": true,
         "issues_events": true,
         "confidential_issues_events": true,
         "merge_requests_events": true,
         "tag_push_events": true,
         "note_events": true,
         "confidential_note_events": true,
         "pipeline_events": true,
         "wiki_page_events": true,
         "job_events": true,
         "properties": {
             "webhook": null,
             "username": null,
             "notify_only_broken_pipelines": null,
             "notify_only_default_branch": null,
             "push_channel": null,
             "issue_channel": null,
             "confidential_issue_channel": null,
             "merge_request_channel": null,
             "note_channel": null,
             "confidential_note_channel": null,
             "tag_push_channel": null,
             "pipeline_channel": null,
             "wiki_page_channel": null
         }
     }
     
  7. Go to GitLab UI, https://gitlab.com/hypnoglow/example/services/slack/edit, and check "Active", "Notify only broken pipelines". Keep "Notify only default branch" unchecked. Click "Save Changes".

  8. Check Slack service:
     curl -sS -XGET "$GITLAB_URL/projects/7822153/services/slack" \
         -H "PRIVATE-TOKEN: $GITLAB_TOKEN" | jq
     {
         "id": 41006774,
         "title": "Slack notifications",
         "created_at": "2018-08-08T19:11:39.973Z",
         "updated_at": "2018-08-08T19:16:49.899Z",
         "active": true,
         "push_events": true,
         "issues_events": true,
         "confidential_issues_events": true,
         "merge_requests_events": true,
         "tag_push_events": true,
         "note_events": true,
         "confidential_note_events": true,
         "pipeline_events": true,
         "wiki_page_events": true,
         "job_events": true,
         "properties": {
             "webhook": "https://google.com",
             "username": "",
             "notify_only_broken_pipelines": "1",
             "notify_only_default_branch": "0",
             "push_channel": "",
             "issue_channel": "",
             "confidential_issue_channel": "",
             "merge_request_channel": "",
             "note_channel": "",
             "confidential_note_channel": "",
             "tag_push_channel": "",
             "pipeline_channel": "",
             "wiki_page_channel": ""
         }
     }
     

Example Project

https://gitlab.com/hypnoglow/example

What is the current bug behavior?

notify_only_broken_pipelines is a boolean property, but has a string values "1" or "0".

What is the expected correct behavior?

notify_only_broken_pipelines should be only either true or false.

Output of checks

This bug happens on GitLab.com