Automatically close outdated GitLab merge request - gitlab

Is there any option to automatically close GitLab merge request after 1 day?
Manually close all the merge requests is not an option since there are many each day.
Thanks in advance

You can create a custom script that uses GitLab API either directly or via client
You'll need to generate private token with Scope: api
Example
Fetch Merge Requests updated before a specific date:
$ PRIVATE_TOKEN=****
$ curl -s -X GET -H "PRIVATE-TOKEN: $PRIVATE_TOKEN" \
"https://gitlab.com/api/v4/merge_requests?state=opened&view=simple&updated_before=2020-02-01T14:09:18.679Z" |\
jq '.[].id'
34520388
33038903
20988416
(put your token instead of ****)
Call Update request for each id in a loop, specifying state_event=close

Related

Continuous deployment gitlab

Line of my .gitlab-ci.yml
IID=$(curl --verbose --request GET --header "Content-Type: application/json" --header "PRIVATE-TOKEN: ${CI_PUSH_TOKEN}" ${APP_REPO_URL}/merge_requests?author_id=xxxxxxxx\&search=${CI_COMMIT_SHORT_SHA} | jq '.[0].iid')
output jq: error (at :0): Cannot index object with number
Please refer to the documentation on Merge requests API and How to use the API to construct a properly formed cURL request with GitLab API before piping the result into jq.
There are a few things going on with your query.
First of all, according to the documentation, the /merge_requests endpoint will
Get all merge requests the authenticated user has access to.
This means that APP_REPO_URL needs to be the GitLab instance URL followed by /api/v4 and not the URL of the specific project.
curl "https://gitlab.example.com/api/v4/merge_requests"
If you need all merge requests for a given project, then you can use
curl "https://gitlab.example.com/api/v4/projects/:id/merge_requests"
where :id is the id of your project. See more at List project merge requests
Then, the search attribute is expecting either a title or a description and not a commit SHA:
Search merge requests against their title and description

How can I make this API call from my Nodejs program?

A member of my team developed this API where you send some numeric values and it gives you back a probability. He deployed it in Heroku and sent me the task of connecting it with our backend, you can make the call from cmd like this:
curl -d "{\"Values\":[[value1,value 2,value 3,value 4,value 5]]}" -H "Content-Type: application/json" -X POST https://apibc1.herokuapp.com/predict
And it will work just like intended, but to be honest I don't know how to make this call in my server file, I'm trying to use the request package in Node but I keep getting the invalid URI error on my logs. An example of the API working from cmd:
And this is what happens when I make the same call in my server.js file:
If you have a working curl you can import it into postman and generate a working code sample for a lot of languages.
Import the curl request
Then click the code button on the right
and select a language/framework option from the dropdown

GitLab api to know the target branch in a merge request

Need to know the target branch from the merge request created, i tried
curl -X GET http://gitlab.com/api/v4/projects/4889/merge_requests/25?target_branch&private_token=************
getting message {"message":"404 Project Not Found"} all the time.

Downloading Event Logs using the API

When downloading Event Logs, is it possible to get them using the API instead of downloading them via the Download CSV button on a web browser?
Is there an API for which it is possible among the URLs below?
https://developer.yahoo.com/flurry/docs/api/code/analyticsapi/
Also, if you plan to add it in the future, please let me know when it is scheduled for completion.
I appreciate your assistance.
There is no API for get Event Logs(raw data) as far as I know.
Workaround:
Downloading Event Logs CSV can be done something like
this with some additional touch. That implementation is for previous version.
After Flurry's renovation at 3/27/2017,
Log in via GET /auth/v1/session with credentials
Get 'flurry-auth-token' from GET /auth/v1/authorize
Call GET ../eventLogCsv with 'flurry-auth-token' to download CSV
I'm a user of Flurry. And hope they support this feature via API soon.
As of moment of writing, Flurry now provides Raw Data Download API, so you can retrive your raw event's data on a periodic basis (but within some limitations - time windows must be less than 1 month, data preparation takes some time, etc.)
Simplified workflow is following:
1. Setup
First of all, you must generate a Programmatic Token (discrabed here https://developer.yahoo.com/flurry/docs/api/code/apptoken/, process is straightforward, except that you'll need to create another user with different role in order to use this token)
2. Making the Request
Specify startTime/endTime for desired time window inside request (within other parameters):
curl -X POST https://rawdata.flurry.com/pulse/v1/rawData
-H 'accept: application/vnd.api+json'
-H 'authorization: Bearer ~~YOUR TOKEN~~'
-H 'cache-control: no-cache'
-H 'content-type: application/vnd.api+json'
-d '{"data": {
"type": "rawData",
"attributes": {
"startTime": "1511164800000",
"endTime": "1511251199000",
"outputFormat": "JSON",
"apiKey": "AAAA1111BBBB2222CCCC"
}
}
}'
If your request was successful (requestStatus equals Acknowledged inside response body), save the id value from response.
3. Checking for data preparation status
Depending on complexity of your app and requested time window, data preparation make take about 30 minutes up to a few hours to be prepared.
You can check status by using:
curl -g https://rawdata.flurry.com/pulse/v1/rawData/26?fields[rawData]=requestStatus,s3URI
-H ‘accept: application/vnd.api+json;’
-H ‘authorization: Bearer ~~YOUR TOKEN~~’
-H ‘cache-control: no-cache’
-H ‘content-type: application/vnd.api+json;’
As soon as your data is ready, response will be following:
{
"data":{
"type":"rawData",
"id":"26",
"attributes":{
"requestStatus":"Success",
"s3URI":"https://flurry-rdd.s3.amazonaws.com/downloads/26.JSON.gz?AWSAccessKeyId=AAAA1111BBBB2222CCCC&Expires=1513101235&Signature=h%2FChXRi5QwmvhUrkpwq2nVKf8sc%3D"
}
}
}
Save s3URI for next step.
4. Retrieving Results
Now you can retrieve archived raw data by using s3URI:
curl -O https://flurry-rdd.s3.amazonaws.com/downloads/26.JSON.gz?AWSAccessKeyId=AAAA1111BBBB2222CCCC&Expires=1513039053&Signature=xbKNnTgpv1odAfVgPRLMyck8UnE%3D
Source: https://developer.yahoo.com/flurry/docs/analytics/rdd/

Gitlab API adding members to a project

I'm experiencing errors when trying to add users to a Gitlab project using the Gitlab API. I'm using Gitlab version 8.11.0 on CentOS 6.8 and I'm not sure if it is a bug or something I am doing wrong.
The following works fine and gives me a list of project members:
curl --header "PRIVATE-TOKEN: top_secret" "https://thegitlabserver.com/api/v3/projects/1/members"
but when trying to add a members with the following, I get an error message:
curl --request POST --header "PRIVATE-TOKEN: top_secret" "https://thegitlabserver.com/api/v3/projects/1/members/myusername?access_level=30"
{"error":"405 Not Allowed"}
Using the web interface I am able to add the user to the project.
It looks like the Gitlab API documentation was incorrect.
As it's a create action, you should send both the user ID and access levels as named parameters (like you would for creating any other resource).
So something like: https://thegitlabserver.com/api/v3/projects/1/members/?user_id=299&access_level=40

Resources