-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·79 lines (65 loc) · 3.31 KB
/
index.js
File metadata and controls
executable file
·79 lines (65 loc) · 3.31 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#! /usr/bin/env node
import dotenv from 'dotenv';
dotenv.config();
import chalk from 'chalk';
import clear from "clear";
import { escape } from 'querystring';
import askQuestions from './src/questions.js';
import fetchData from './src/fetchData.js';
import extractContent from './src/extractContent.js';
import { getHighlights } from './src/createJitNotes.js';
import { getSummaryTable } from './src/createJitNotes.js';
import { getJiraLinks } from './src/createJitNotes.js';
import { getPrLinks } from './src/createJitNotes.js';
import { getRepoLink } from './src/createJitNotes.js';
import figletPkg from 'figlet';
const { textSync } = figletPkg;
import { copyTemplate } from './src/templates.js';
import { createPlaceholders } from './src/placeholders.js';
import { replacePlaceholders } from './src/templates.js';
import { Spinner } from 'cli-spinner';
const spinner = new Spinner(`${chalk.yellow('Processing.. %s')}`);
spinner.setSpinnerString('⣾⣽⣻⢿⡿⣟⣯⣷');
// Clear console and show welcome message
clear();
console.log(chalk.yellow(textSync("Jit Notes!", { horizontalLayout: "fitted", font: "Standard" })));
console.log(chalk.green(`Linking Jira tickets with GitHub PRs to show you
the whole development story. Let's get started!\n`));
const start = async () => {
try {
// Ask relevant questions
const answers = await askQuestions();
const { jiraProject, githubRepo, ticketStatus, startDate, endDate, jiraToken, githubToken } = answers;
console.log("");
spinner.start();
// Create Jira and GitHub API URLs
const jiraReleaseQuery = escape(`project = ${jiraProject} AND issuetype != Task AND status = "${ticketStatus}" ORDER BY issuetype DESC`);
const jiraUrl = `https://jira.corp.adobe.com/rest/api/2/search?jql=${jiraReleaseQuery}&maxResults=150`;
const githubUrl = `https://api.github.com/search/issues?q=repo:${githubRepo}+is:pr+is:merged+merged:${startDate}..${endDate}&sort=created&order=asc`;
// Get Jira and GitHub data
const jiraData = await fetchData(jiraUrl, process.env.JIRA_TOKEN || jiraToken, 'jira');
const githubData = await fetchData(githubUrl, process.env.GITHUB_TOKEN || githubToken, 'github');
const jiraIssues = await extractContent(jiraData, 'jira');
const githubPRs = await extractContent(githubData, 'github');
// Pass Jira and GitHub data to create sections for release notes template
const highlights = getHighlights(jiraIssues, githubPRs);
const summaryTable = getSummaryTable(jiraIssues, githubPRs);
const jiraLinks = getJiraLinks(jiraIssues, githubPRs);
const githubLinks = getPrLinks(jiraIssues, githubPRs);
const githubReleasesLink = getRepoLink(githubRepo);
// Replace placeholders in template
createPlaceholders(answers, highlights, summaryTable, jiraLinks, githubLinks, githubReleasesLink);
copyTemplate(jiraProject);
replacePlaceholders(answers);
// Push feedback to console
console.log(`${chalk.white('✔ Jit notes created successfully!\n')}`);
console.log('\x1b[33m%s\x1b[0m', `View the new CHANGELOG.md in your current directory.\n`);
} catch (error) {
console.log(`${chalk.red('\nPlease correct the following code-related errors and try again.')}`);
console.error(`${chalk.red(error)}`);
} finally {
console.log(`${chalk.white('✔ Exiting...\n')}`);
spinner.stop(true);
}
};
start();