3

I want to know which application/software version fixes the bug. In other words, I have bug/issue ID and want to find a version number.

I start by doing: GET projects/*cut*/issues/42/closed_by which gives me a merge request which lists this issue as fixed:

[
  {
    "id":"*cut*",
    "iid":31,
    "project_id":"*cut*",
    "title":"Demo merge request",
    "description":"Fixes #42",
    "state":"merged",
    "created_at":"2023-05-16T13:18:27.079Z",
    "updated_at":"2023-05-16T13:18:44.719Z",
    "merged_at":"2023-05-16T13:18:44.041Z",
    "closed_by":null,
    "closed_at":null,
    "target_branch":"master",
    "source_branch":"WorkFor42",
    "user_notes_count":0,
    "upvotes":0,
    "downvotes":0,
    "assignees":[],
    "assignee":null,
    "reviewers":[],
    "source_project_id":"*cut*",
    "target_project_id":"*cut*",
    "labels":[],
    "draft":false,
    "work_in_progress":false,
    "milestone":null,
    "merge_when_pipeline_succeeds":false,
    "merge_status":"can_be_merged",
    "detailed_merge_status":"not_open",
    "sha":"c8ddb6b51d500893f05ae40c646399d33408dad9",
    "merge_commit_sha":"1fa7f1a368af806fa8945d00fe99a08608e3d3ba",
    "squash_commit_sha":null,
    "discussion_locked":null,
    "should_remove_source_branch":true,
    "force_remove_source_branch":true,
    "reference":"!31",
    "references":{
      "short":"!31",
      "relative":"!31",
      "full":"*cut*/test!31"
    },
    "web_url":"https://*cut*/-/merge_requests/31",
    "time_stats":{
      "time_estimate":0,
      "total_time_spent":0,
      "human_time_estimate":null,
      "human_total_time_spent":null
    },
    "squash":false,
    "squash_on_merge":false,
    "task_completion_status":{
      "count":0,
      "completed_count":0
    },
    "has_conflicts":false,
    "blocking_discussions_resolved":true,
    "approvals_before_merge":null
  }
]

Now, how do I move forward? I would like to get a release name (tag name), which includes this merge request.

I also tried to list all releases via: GET projects/*cut*/releases and then do GET projects/*cut*/issues?state=closed&release_tag=each-name-from-prev-results for each of the returned release. Unfortunately, the release_tag is ignored by the projects/id/issues API.

General Grievance
  • 4,555
  • 31
  • 31
  • 45

1 Answers1

2

That does not seem to be natively supported by GitLab API, which means you can either:

  1. Use Commits API

    You already have the merge_commit_sha from the merge request response. You can use this to get the commit details with the GitLab Commits API.

    GET /projects/:id/repository/commits/:sha

    This will give you details about the commit, including the date it was committed. Then, use the GitLab Tags API to get all the tags in the repository.

    GET /projects/:id/repository/tags

    The response from this API includes the commit details associated with each tag and the date when the tag was created. You can compare the commit date from the commit API with the tag creation dates to find the tag (version) in which your commit was first included.
    Note that this could potentially give inaccurate results if tags are not created in chronological order.

  2. Use Commits and Releases APIs:

    Similar to the first method, you would start by getting the commit details using the merge_commit_sha and the Commits API. Then, instead of getting all tags, use the Releases API to get all releases.

    GET /projects/:id/releases

    This will give you a list of all the releases, including the tag name and the commit SHA associated with each release. You can search through these releases to find the one with the matching commit SHA.

Both of these methods involve looping through either all tags or all releases, so they might not be very efficient if you have many tags or releases.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250