xanzy / go-gitlab

GitLab Go SDK
Apache License 2.0
2.42k stars 960 forks source link

Question regarding Slack Application support #2038

Closed jgangemi closed 1 month ago

jgangemi commented 1 month ago

i'm looking through services.go and the SetSlackApplicationOptions struct doesn't seem to align w/ the the response i get from the following:

curl -s -X GET --header "PRIVATE-TOKEN: <TOKEN>" https://gitlab.com/api/v4/projects/<project-id>/integrations/gitlab-slack-application

sample json response

{
  "id": 125574635,
  "title": "GitLab for Slack app",
  "slug": "gitlab-slack-application",
  "created_at": "2023-09-26T18:09:10.011Z",
  "updated_at": "2023-10-26T22:08:26.585Z",
  "active": true,
  "commit_events": false,
  "push_events": false,
  "issues_events": false,
  "incident_events": false,
  "alert_events": false,
  "confidential_issues_events": false,
  "merge_requests_events": false,
  "tag_push_events": false,
  "deployment_events": false,
  "note_events": false,
  "confidential_note_events": false,
  "pipeline_events": true,
  "wiki_page_events": false,
  "job_events": false,
  "comment_on_event_enabled": true,
  "inherited": false,
  "vulnerability_events": false,
  "properties": {
    "channel": null,
    "notify_only_broken_pipelines": false,
    "branches_to_be_notified": "all",
    "labels_to_be_notified": "",
    "labels_to_be_notified_behavior": "match_any",
    "push_channel": "",
    "issue_channel": "",
    "confidential_issue_channel": "",
    "merge_request_channel": "",
    "note_channel": "",
    "confidential_note_channel": "",
    "tag_push_channel": "",
    "pipeline_channel": "#channel",
    "wiki_page_channel": "",
    "deployment_channel": "",
    "incident_channel": "",
    "vulnerability_channel": "",
    "alert_channel": ""
  }
}

am i missing something obvious (or not so obvious as i am new to go) or do the two just not align?

if they do no align, what would be the proper way to go about adding support for this as altering the struct to support the following json would be a breaking change?

jgangemi commented 1 month ago

digging a little bit deeper, it looks like only

"channel": null,
"notify_only_broken_pipelines": false,
"branches_to_be_notified": "all",

have moved to properties, so would the non-breaking change for this to be to do something like this:

type SetSlackApplicationOptions struct {
    AlertEvents               *bool   `url:"alert_events,omitempty" json:"alert_events,omitempty"`
    IssuesEvents              *bool   `url:"issues_events,omitempty" json:"issues_events,omitempty"`
    ConfidentialIssuesEvents  *bool   `url:"confidential_issues_events,omitempty" json:"confidential_issues_events,omitempty"`
    MergeRequestsEvents       *bool   `url:"merge_requests_events,omitempty" json:"merge_requests_events,omitempty"`
    NoteEvents                *bool   `url:"note_events,omitempty" json:"note_events,omitempty"`
    ConfidentialNoteEvents    *bool   `url:"confidential_note_events,omitempty" json:"confidential_note_events,omitempty"`
    DeploymentEvents          *bool   `url:"deployment_events,omitempty" json:"deployment_events,omitempty"`
    IncidentsEvents           *bool   `url:"incidents_events,omitempty" json:"incidents_events,omitempty"`
    PipelineEvents            *bool   `url:"pipeline_events,omitempty" json:"pipeline_events,omitempty"`
    PushEvents                *bool   `url:"push_events,omitempty" json:"push_events,omitempty"`
    TagPushEvents             *bool   `url:"tag_push_events,omitempty" json:"tag_push_events,omitempty"`
    VulnerabilityEvents       *bool   `url:"vulnerability_events,omitempty" json:"vulnerability_events,omitempty"`
    WikiPageEvents            *bool   `url:"wiki_page_events,omitempty" json:"wiki_page_events,omitempty"`
        Properties  struct {
             Channel                   *string `url:"channel,omitempty" json:"channel,omitempty"`
             <other property fields>
        }, `json:properties`

        // Deprecated: Moved to 'Properties' struct
    Channel                   *string `url:"channel,omitempty" json:"channel,omitempty"`
    // Deprecated: Moved to 'Properties' struct
        NotifyOnlyBrokenPipelines *bool   `url:"notify_only_broken_pipelines,omitempty" json:"notify_only_broken_pipelines,omitempty"`
    // Deprecated: Moved to 'Properties' struct
        BranchesToBeNotified      *string `url:"branches_to_be_notified,omitempty" json:"branches_to_be_notified,omitempty"`
    // Deprecated: This parameter has been replaced with BranchesToBeNotified.
    NotifyOnlyDefaultBranch *bool `url:"notify_only_default_branch,omitempty" json:"notify_only_default_branch,omitempty"`
}
jgangemi commented 1 month ago

ok - i figured this out. the slack structs are incorrect as all but the notify_only_broken_pipelines attribute are defined in the Service struct. instead those *Event fields should be *Channel and strings.