Add MR comment (gitlab)

Adds a comment to a Gitlab merge request (MR)

Script gitlab

by jaumebosch628 ยท 7/8/2024

  • Submitted by jaumebosch628 Bun
    Created 689 days ago
    1
    type Gitlab = {
    2
      baseUrl: string;
    3
      token: string;
    4
    };
    5
    export async function main(
    6
      glab: Gitlab,
    7
      projectId: number,
    8
      mergeRequestId: number,
    9
      comment: string
    10
    ) {
    11
      const url = `${glab.baseUrl}/api/v4/projects/${projectId}/merge_requests/${mergeRequestId}/notes`;
    12
      const response = await fetch(url, {
    13
        method: 'POST',
    14
        headers: {
    15
          'Content-Type': 'application/json',
    16
          'Authorization': `Bearer ${glab.token}`,
    17
        },
    18
        body: JSON.stringify({ body: comment }),
    19
      });
    20
    
    
    21
      if (!response.ok) {
    22
        throw new Error(`Error ${response.status}: ${response.statusText}`);
    23
      }
    24
    
    
    25
      return await response.json();
    26
    }
    27
    
    
    28