How To Create Issue Label Milestone In GitLab Using API
Hello Everyone
Welcome to CloudAffaire and this is Debjeet.
In the last blog post, we have discussed how to import a GitHub repository into a GitLab project.
https://cloudaffaire.com/how-to-import-a-github-repository-in-gitlab/
In this blog post, we will discuss how to create issue, label and milestones in GitLab. This demo is created using API as we are taking a programmatic approach to cover most of the demo. But we have also provided the console steps as well so that if you want to perform the demo from GitLab console, you can do the same.
What Is Issue In GitLab?
Issues are the fundamental medium for collaborating on ideas and planning work in GitLab. The GitLab issue tracker is an advanced tool for collaboratively developing ideas, solving problems, and planning work. Issues can allow you and your team to share and discuss proposals before, and during, their implementation. However, they can be used for a variety of other purposes, customized to your needs and workflow.
Issues are always associated with a specific project, but if you have multiple projects in a group, you can also view all the issues collectively at the group level.
Using issue you can:
- Discussing the implementation of a new idea
- Tracking tasks and work status
- Accepting feature proposals, questions, support requests, or bug reports
- Elaborating on new code implementation
How To Create An Issue In GitLab:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
########################### ## GitLab Issue Tracking ## ########################### ## Prerequisites: GitLab Access Token ## https://cloudaffaire.com/how-to-create-a-gitlab-project-using-api/ ## One CentOs system with internet access ## git, curl and jq package installed ## ------------------------------------ ## Create A GitLab Project To Play With ## ------------------------------------ ## Create a project in GitLab ## GitLab Console => Projects => Your Projects => New Project => PROJECT_ID=$(curl --silent --header "PRIVATE-TOKEN: -XPOST "https://gitlab.com/api/v4/projects?name=cloudaffaire&visibility=private&initialize_with_readme=true" | jq '.id') ## ------------ ## GitLab Issue ## ------------ ## Create a new issue in your project ## GitLab Console => Projects => Your Projects => ## => Left navigation pane => Issue => New Issue curl -s --request POST --header "PRIVATE-TOKEN: --data '{"title": "myissue", "description": "this issue created through api", "due_date": "2030-03-03" }' \ "https://gitlab.com/api/v4/projects/$PROJECT_ID/issues" | jq '.' ## List all issues in your project ## GitLab Console => Projects => Your Projects => ## => Left navigation pane => Issue => List curl -s --request GET --header "PRIVATE-TOKEN: "https://gitlab.com/api/v4/projects/$PROJECT_ID/issues" | jq -r '.[].title, .[].description, .[].labels, .[].milestone' |
What Is Label In GitLab?
Labels allow you to categorize epics, issues, and merge requests using descriptive titles like bug, feature request, or docs, as well as customizable colors. They allow you to quickly and dynamically filter and manage epics, issues, and merge requests, and are a key part of issue boards. You can use labels to help search in lists of issues, merge requests, and epics, as well as search in issue boards.
There are two types of labels in GitLab:
- Project labels can be assigned to issues and merge requests in that project only.
- Group labels can be assigned to issues and merge requests in any project in the selected group or its subgroups.
How To Create A Label In GitLab:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
## ------------ ## GitLab Label ## ------------ ## Create a new label to your project ## GitLab Console => Projects => Your Projects => ## => Left navigation pane => Issue => Label => New Label curl -s --request POST --header "PRIVATE-TOKEN: --data '{"name": "mylabel", "color": "#0088CF", "description": "label created through api"}' \ "https://gitlab.com/api/v4/projects/$PROJECT_ID/labels" | jq '.' ## List all labels in your project ## GitLab Console => Projects => Your Projects => ## => Left navigation pane => Issue => Label curl -s --request GET --header "PRIVATE-TOKEN: "https://gitlab.com/api/v4/projects/$PROJECT_ID/labels" | jq -r '.[].name' ## Add a label to an issue ## GitLab Console => Projects => Your Projects => ## => Left navigation pane => Issue => ISSUE_IID=$(curl -s --request GET --header "PRIVATE-TOKEN: "https://gitlab.com/api/v4/projects/$PROJECT_ID/issues" | jq -r '.[].iid') && curl -s --request PUT --header "PRIVATE-TOKEN: --data '{"labels": "mylabel", "description": "label added to the issue"}' \ "https://gitlab.com/api/v4/projects/$PROJECT_ID/issues/$ISSUE_IID" | jq '.' |
What Is Milestone In GitLab?
Milestones in GitLab are a way to track issues and merge requests created to achieve a broader goal in a certain period of time. Milestones allow you to organize issues and merge requests into a cohesive group, with an optional start date and an optional due date.
There are two types of Milestone in GitLab:
- Project milestones can be assigned to issues or merge requests in that project only.
- Group milestones can be assigned to any issue or merge request of any project in that group.
How To Create A Milestone In GitLab:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
## ---------------- ## GitLab Milestone ## ---------------- ## Create a new milestone to your project ## GitLab Console => Projects => Your Projects => ## => Left navigation pane => Issue => Milestones => New milestone curl -s --request POST --header "PRIVATE-TOKEN: --data '{"title": "mymilestone", "description": "this milestone created through api", "due_date": "2030-03-03"}' \ "https://gitlab.com/api/v4/projects/$PROJECT_ID/milestones" | jq '.' ## List all Milestones in your project ## GitLab Console => Projects => Your Projects => ## => Left navigation pane => Issue => Milestones curl -s --request GET --header "PRIVATE-TOKEN: "https://gitlab.com/api/v4/projects/$PROJECT_ID/milestones" | jq -r '.[].title' ## Create a new issue with milestone in your project ## GitLab Console => Projects => Your Projects => ## => Left navigation pane => Issue => New Issue MID=$(curl -s --request GET --header "PRIVATE-TOKEN: "https://gitlab.com/api/v4/projects/$PROJECT_ID/milestones" | jq -r '.[].id') && curl -s --request POST --header "PRIVATE-TOKEN: "https://gitlab.com/api/v4/projects/$PROJECT_ID/issues?title=mynewissue&milestone_id=$MID" | jq '.' ## Close the latest issue attached with a milestone ## GitLab Console => Projects => Your Projects => ## => Left navigation pane => Issue => ISSUE_IID=$(curl -s --request GET --header "PRIVATE-TOKEN: "https://gitlab.com/api/v4/projects/$PROJECT_ID/issues" | jq -r '.[0].iid') && curl -s --request PUT --header "PRIVATE-TOKEN: "https://gitlab.com/api/v4/projects/$PROJECT_ID/issues/$ISSUE_IID?state_event=close" | jq '.' ## Delete your GitLab project ## GitLab Console => Projects => Your Projects => ## => Left navigation pane => Settings => General => Advanced => Remove project curl --silent --header "PRIVATE-TOKEN: -XDELETE "https://gitlab.com/api/v4/projects/$PROJECT_ID" | jq '.' |
Hope you enjoyed this article. In the next blog post, we will discuss how to add an SSH key in the GitLab profile.
To get more details on GitLab you can follow the below link.
https://docs.gitlab.com/ee/README.html
To Get more details on Git you can follow the below links.
https://cloudaffaire.com/category/devops/git/