matrix-org / matrix-hookshot

A bridge between Matrix and multiple project management services, such as GitHub, GitLab and JIRA.
https://matrix-org.github.io/matrix-hookshot/
Apache License 2.0
283 stars 68 forks source link

Add Support for GitLab Pipeline #796

Open Jmcclaskey opened 1 year ago

Jmcclaskey commented 1 year ago

It looks like you are not supporting the 'pipeline' trigger for Gitlab in your events https://github.com/matrix-org/matrix-hookshot/blob/main/src/Gitlab/WebhookTypes.ts this would be super helpful for me, I am adding a sample code of what to add to fix it.

WebhookTypes add:

export interface IGitLabWebhookPipelineEvent {
    object_kind: "pipeline";
    object_atributes:
            id: int //for referencing the pipeline
            ref: string
            source: string
            status: string
            detailed_status: string // Idk if this is helpful but might be for saying what went wrong
    user_id: number;
    user_name: string;
    user_email: string;
    project: IGitlabProject;
    repository: IGitlabRepository;
    commits: {      // you could leave but I would say remove it
      id: string,
      message: string,
      title: string,
      timestamp: string,
      url: string,
      author: {
        "name": string,
        "email": string
      },
      added: string[],
      modified: string[],
      removed: string[],
    },
    builds: [
        {
        stage: string
        name: string
        duration: float?? // not sure here
         }
    ]
}

Idk how you you want to handle the pipelines for the GitLabRepo but I would either ignore all status other than 'failure' and 'success' as its easier to just post the results that posting for all the 4 statuses you might see i.e. running, pending, failed, and success. On failure you should use the builds field to state where and why it failed, you can see more about the gitlab pipeline api here https://docs.gitlab.com/ee/api/pipelines.html. not sure how you handle the actual post message to hookshot but this seems like the harder part.

It would be cool it you could also add the support for when and why the pipeline was triggered and use matrix threads to refer back to the message for when the pipeline started.