Properly copies issues over now (minus due date, lol)

This commit is contained in:
Alan O'Cull 2024-01-13 02:12:20 -05:00
parent d281200376
commit 97f24641e0
3 changed files with 20 additions and 17 deletions

View File

@ -29,12 +29,8 @@ fetch(url).then((res) => {
_.forEach(data, (ticket) => {
const issue = Issue.fromGitea(ticket, CONFIG['repository-default']);
database.push(issue);
console.log(issue);
console.log(issue.toJira(uGiteaToJira, SECRETS['jira-project']));
// Now, search Jira issues to make sure this isn't already duplicated
const jiraIssueSearch = `project = "AAA" and summary ~ "${issue.title_jira}"\nORDER BY created DESC`
const jiraIssueSearch = `project = "${SECRETS['jira-project']}" and summary ~ "${issue.title_jira}"\nORDER BY created DESC`
jiraFetch(`issue/picker?currentJQL=${jiraIssueSearch}`, 'GET').then((jiraSearch) => {
jiraSearch.json().then((searchJSON) => {
@ -55,9 +51,11 @@ fetch(url).then((res) => {
jiraFetch('issue', 'POST', issue.toJira(uGiteaToJira, SECRETS['jira-project'])).then((res) => {
res.json().then((createdIssue) => {
console.log(createdIssue);
issue.id_jira = createdIssue['id'];
issue.id_jira = createdIssue['key'];
})
})
} else {
console.log(`Issue "${issue.title_jira}" already existed, skipping`);
}
})
})

View File

@ -26,7 +26,7 @@ class Issue {
const labels: string[] = [];
_.forEach(obj['labels'], (label: any) => {
labels.push(label['id'])
labels.push(label['name'])
});
// Fetch assignees
@ -60,7 +60,7 @@ class Issue {
* @summary Converts this to a Jira JSoN object
* https://developer.atlassian.com/server/jira/platform/jira-rest-api-examples/#creating-an-issue-examples
*/
public toJira(remap: any, parent: string): any {
public toJira(remap: any, projectKey: string): any {
const obj: any = {
"labels": this.labels,
"summary": this.title_jira,
@ -82,19 +82,23 @@ class Issue {
"reporter": {
"id": remap[this.reporter]
},
"parent": {
"key": parent
"project": {
"key": projectKey
},
"issuetype": {
// If there is a bug inside the labels, count the issue as a bug, else it's a task
"name": this.labels.includes('Bug') ? 'Bug' : 'Task'
}
}
if (this.assignees.length > 0) {
obj['assignee'] = remap[this.assignees[0]];
}
if (this.dueDate !== '') {
obj['duedate'] = this.dueDate.slice(0, this.dueDate.indexOf('T'));
// obj['duedate'] = this.dueDate.slice(0, this.dueDate.indexOf('T'));
}
return {"fields": obj, "update": {}};
return {"fields": obj};
}
public get title_jira(): string {

View File

@ -6,19 +6,20 @@ const OAUTH_JIRA = `${SECRETS['jira-email']}:${SECRETS['jira-token']}`;
const OAUTH_GITEA = `token=${SECRETS['gitea-token']}`;
function jiraFetch(protocol: string, method: string = 'POST', body: any = null) {
const options: any = {
const options: RequestInit = {
method: method,
headers: {
'Authorization': `Basic ${Buffer.from(OAUTH_JIRA).toString('base64')}`,
'Accept': 'application/json'
}
'Accept': 'application/json',
'Content-Type': 'application/json',
},
};
if (body !== null) {
options['body'] = JSON.stringify(body);
options.body = JSON.stringify(body);
}
return fetch(`https://${SECRETS['jira-site']}.atlassian.net/rest/api/3/${protocol}`, options);
return fetch(`https://${SECRETS['jira-site']}.atlassian.net/rest/api/3/${protocol}`, <any>options);
}
export { jiraFetch };