forked from guilhermeandraschko/auto-create-pr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
37 lines (32 loc) · 1.24 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { Octokit } from "@octokit/rest";
import getBody from "./get-body.js";
import getCommandLineArgs from "./get-command-line-args.js";
import getJiraBodyVars from "./get-jira-body-vars.js";
import readConfigFile from "./read-config-file.js";
console.log('reading config file ...');
const configvars = readConfigFile();
console.log('done.');
console.log('reading command line args ...');
const {branch, jiracard, draft} = getCommandLineArgs();
const isdraft = draft == 'draft' ? true : false;
console.log('done.');
console.log('rendering body template ...');
const bodyvars = await getJiraBodyVars(jiracard, configvars);
const bodyy = await getBody(configvars, bodyvars);
console.log('done.');
console.log('creating pr...');
try {
const octokit = new Octokit({ auth: configvars.get('token') });
const { data: pullRequest } = await octokit.rest.pulls.create({
owner: configvars.get('owner'),
repo: configvars.get('repo'),
title: `[${jiracard + " - " + bodyvars.description + "]" || 'PR'}`,
body: `${bodyy}`,
head: `${branch}`,
base: configvars.get('base'),
draft: isdraft
});
console.log('done. Go to: ' + pullRequest.html_url);
} catch(e) {
console.log('failed. Response ' + e.message);
}