Get the issues mentioned in the merge request - gitlab

Is there an API in gitlab that can fetch the issues mentioned in the merge request? I keep looking at the documentation, but I can't find it.
I'd like to take advantage of this and try to automate it.

Maybe the Gitlab merge request API is what you need https://docs.gitlab.com/ee/api/merge_requests.html#list-issues-that-close-on-merge
You can get all the issues that would be closed by merging the provided merge request.
GET /projects/:id/merge_requests/:merge_request_iid/closes_issues
Example command:
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/<project_id>/merge_requests/<merge_request_id>/closes_issues"

Related

How can I get all the branches of a project using Gitlab API?

Trying to get all the branches under a project using GitLab API, but I can see only 20 branches are returned. How can I get the complete list of all the branches? I am using the following API.
curl --header "PRIVATE-TOKEN: <token>" "https://gitlab.com/api/v4/projects/1521/repository/branches"
Found the solution under pagination in the official Gitlab API documentation, by default we get 20 results, we can increase the number of results by using per_page in our API link as follows.
https://gitlab.com/api/v4/projects/<Project_id>/repository/branches?per_page=50
Getting branches is limited to 20 branches. In order to get all branches use query parameters like below:
https://gitlab.com/api/v4/projects/2009901/repository/branches/?page=2
https://gitlab.com/api/v4/projects/2009901/repository/branches/?per_page=100
Documentation can be found here:
https://docs.gitlab.com/ee/api/#pagination
This is missing in the Branches API documentation unfortunately:
https://docs.gitlab.com/ee/api/branches.html

Getting repository contents using GitHub API

I know there is an API for getting repository content. But my use case is I need to get the whole repository and display it in my UI like GitHub UI. Similar to GitHub UI, I need my repository to be displayed in my UI. Is there any API I can use to get the whole repository so I can display that in my UI.
I tried this API.
curl \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
https://api.github.com/repos/OWNER/REPO/zipball/REF
But it gives separate file contents. I need the whole repo.
Getting the all repository remains easier with a simple git clone. No need for an API call there.
If, as mentioned in this 2016 octokit issue, you cannot clone through GitHub API, you could use libgit2sharp to integrate the clone operation in your application.

Get issues on a date range from Github enterprise API

I want to get a list of issues that have been created in a specific date range using the Github enterprise api. What I want to do would be the equivalent of doing a search on the issues page as shown on the image below:
I have tried the following command: curl -H "Authorization: token myToken" "https://github.mydomain.com/api/v3/repos/owner/repo/issues?state=all&since=2015-09-01" > issues.json but that does not give me what i need because the parameter since according to the Api docs is described as:
Only issues updated at or after this time are returned. This is a timestamp in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ
Thanks in advance!
So after lots of googling and reading through the Github API docs I figured it out. What i needed for this was the Github Search API. The first thing i did was figure out what endpoints where available to me on my enterprise API as described in this stackoverflow post. So I used the following command to do that:
curl -H "Authorization: token [myToken]" "https://github.mydomain.com/api/v3/"
One of the endpoints returned in the response was:
"issue_search_url": "https://github.mydomain.com/api/v3/search/issues?q={query}{&page,per_page,sort,order}"
Using that endpoint, I constructed the following command that gave me what I needed:
curl -H "Authorization: token [myToken]" "https://github.mydomain.com/api/v3/search/issues?page=1&per_page=100&sort=created&order=asc&q=repo:[Owner]/[RepoName]+is:issue+created:>=2015-09-01"
Let's break down the parameters (anything after the ? sign):
page=1&per_page=100: The default number of results for this request is 30 per page. In my case I had 664 results. So I needed to do multiple request specifying which page (page=1) and how many results I wanted for that request (per_page=100) until i got all of them. In my case i did 7 request with the above url each time changing the page number. For more info see the Github docs on Pagination
&sort=created&order=asc: Sor by the created date in ascending order (oldest first). See Github Search API and Searching Issues
q=repo:[Owner]/[RepoName]+is:issue+created:>=2015-09-01: Form a search query (q=) that limits the search to issues (is:issue) created from 2015-09-01 and on (created:>=2015-09-01) in the repo Owner/Name (repo:[Owner]/[RepoName])
Hope this helps others as I have found that the Github api docs are not very clear.

How can I GET a json of all the projects I have access to using Gitlab API?

I want to get a json file with all the projects that appear on my Dashboard and that I have developer access to. I though it would be a very simple job using the Gitlab API, more specifically the projects API, but so far, I can't. Is it possible?
Note : I generated a token with api scope.
Here's what I tried and the results :
curl --header "PRIVATE-TOKEN: XXXXX" https://gitlab.com/api/v3/projects
It gives me all the projects I don't own but I have master access to. It doesn't include the ones I have developer/other access to. The result is the closest to what I'm looking for so far.
curl --header "PRIVATE-TOKEN: XXXXX" https://gitlab.com/api/v4/projects
It gives me a list of projects I seem to have access to, even though I have no idea what they are.
curl --header "PRIVATE-TOKEN: XXXXX" https://gitlab.com/api/v4/users/myUser/projects
It gives me all the projects I own. I thought that one would work since the documentation says Get a list of visible projects for the given user. I also tried with the membership attribute set to true or false, but there is no difference.
Any advice/help would be appreciated!
I know this is old question, but maybe other will stumble over this as I just did.
My solution was adding the per_page option
curl -s -X GET -H 'Private-Token: ' 'https://gitlab.com/api/v4/projects?per_page=100'

Dashboard with builds, commits and files from GitLab

How do I do dashboard with information from my GitLab repo? I don't know how I get information about builds, commits and files and create dashboard with this information. Any idea? Thank you very much.
You can use GitLab's API to obtain the information from GitLab. You will need to have an user account which can access a particular project. Get this user's "Private Token" from the /profile/account page and then you can make requests for which you would get a JSON response.
Retrieving latest commits
curl -H "PRIVATE-TOKEN: [TOKEN]" \
"https://[HOST]/api/v3/projects/[PROJECT ID]/repository/commits"
Retrieving latest builds
curl -H "PRIVATE-TOKEN: [TOKEN]" \
"https://[HOST]/api/v3/projects/[PROJECT ID]/repository/builds"
These are examples using curl. Depending on the programming language you are going to use, you will have to make a GET request while setting a HTTP header (that is what -H in my example stands for) named PRIVATE-TOKEN.

Resources