gitlab-gitea-api/index.js
2020-09-20 14:14:35 +02:00

65 lines
1.4 KiB
JavaScript
Executable File

#!/usr/bin/env -S node
const rek = require('rek/node')
const args = require('yargs').argv
const wait = (time) => new Promise((resolve) => setTimeout(resolve, time))
if (!args.i || !args.n || !args.r) {
throw new Error('missing args')
}
const gitlabToken = 'x_B9BwBcyCJ1TFY4UwBp'
const giteaToken = '444eb7c86cc09e16fc3da30827d806162061928d'
;(async () => {
const issues = await rek(
`https://gitlab.bitmill.io/api/v4/projects/${args.i}/issues?private_token=${gitlabToken}&per_page=100`,
).json()
issues.sort((a, b) => {
if (a.iid > b.iid) {
return 1
}
if (a.iid < b.iid) {
return -1
}
return 0
})
for (const issue of issues) {
try {
const result = await rek
.post(
`https://gitea.bitmill.io/api/v1/repos/${args.n}/${args.r}/issues`,
{
assignee: issue.assignee?.username,
body: issue.description,
closed: issue.state == 'closed',
due_on: issue.due_date,
title: issue.title,
},
{
headers: {
Authorization: `token ${giteaToken}`,
},
},
)
.json()
console.dir(result.number)
if (result.number !== issue.iid) {
console.dir(result)
}
await wait(1000)
} catch (error) {
console.log(error)
console.log(error.message)
break
}
}
})()