Skip to content

Instantly share code, notes, and snippets.

@acidsound
Last active December 24, 2020 02:33
Show Gist options
  • Save acidsound/1fd31083e1aecc32d88d3fc90ec5499f to your computer and use it in GitHub Desktop.
Save acidsound/1fd31083e1aecc32d88d3fc90ec5499f to your computer and use it in GitHub Desktop.
gitlab에서 merge request 목록 가져오기
PRIVATE_TOKEN=XXXXXXXXXXXX
API=https://XXXXXX/api/v4
const dotenv = require("dotenv");
const jsonexport = require("jsonexport");
const gitlab = require("node-gitlab");
const env = dotenv.config()?.parsed;
const client = gitlab.createPromise({
api: env.API,
privateToken: env.PRIVATE_TOKEN,
});
if (process.argc < 3) {
console.log("Usage: main.js [ids]");
return;
}
const projects = Array.from(process.argv.splice(2), (id) => ({ id }));
const main = async function (client) {
const per_page = 20;
const mrs = await Promise.all(
projects.map(async ({ id }) => {
let mr = [];
let res = [];
for (let page = 1; ; page++) {
res = await client.mergeRequests.list({ id, page });
mr = [...mr, ...res.filter(({ state }) => state === "merged")];
if (res.length < per_page) break;
}
return mr.map(
({
id,
iid,
title,
description,
labels,
sha,
web_url,
merged_by,
merged_at,
}) => ({
id,
iid,
title,
description,
labels,
sha,
web_url,
merged_by,
merged_at,
})
);
})
);
jsonexport(mrs[0], (err, csv) => console.log(csv));
};
main(client);
{
"name": "MRTracker",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node main.js",
"cad": "node main.js 77 > output.csv",
"web": "node main.js 58 > output.csv"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"dotenv": "^8.2.0",
"jsonexport": "^3.0.1",
"node-gitlab": "^1.6.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment