From 10ff3db1ab76b462df99760e0166d4d8ed9f237b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Tue, 5 Mar 2019 15:53:25 +0100 Subject: [PATCH] Added first iteration/poc of changelog task --- package.json | 4 +++- scripts/cli/index.ts | 8 ++++++++ scripts/cli/tasks/changelog.ts | 34 ++++++++++++++++++++++++++++++++++ yarn.lock | 5 +++++ 4 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 scripts/cli/tasks/changelog.ts diff --git a/package.json b/package.json index c5136cf5e02..269328d5221 100644 --- a/package.json +++ b/package.json @@ -73,6 +73,7 @@ "html-webpack-plugin": "^3.2.0", "husky": "^1.3.1", "inquirer": "^6.2.2", + "issue-regex": "^3.0.0", "jest": "^23.6.0", "jest-date-mock": "^1.0.6", "lint-staged": "^8.1.3", @@ -140,7 +141,8 @@ "gui:releasePrepare": "ts-node --project ./scripts/cli/tsconfig.json ./scripts/cli/index.ts gui:release", "gui:publish": "cd packages/grafana-ui/dist && npm publish --access public", "gui:release": "ts-node --project ./scripts/cli/tsconfig.json ./scripts/cli/index.ts gui:release -p", - "cli:help": "ts-node --project ./scripts/cli/tsconfig.json ./scripts/cli/index.ts --help" + "cli:help": "ts-node --project ./scripts/cli/tsconfig.json ./scripts/cli/index.ts --help", + "cli:changelog": "ts-node --project ./scripts/cli/tsconfig.json ./scripts/cli/index.ts core:changelog" }, "husky": { "hooks": { diff --git a/scripts/cli/index.ts b/scripts/cli/index.ts index 559f7295ad0..108f7877569 100644 --- a/scripts/cli/index.ts +++ b/scripts/cli/index.ts @@ -4,6 +4,7 @@ import chalk from 'chalk'; import { startTask } from './tasks/core.start'; import { buildTask } from './tasks/grafanaui.build'; import { releaseTask } from './tasks/grafanaui.release'; +import { changelogTask } from './tasks/changelog'; program.option('-d, --depreciate ', 'Inform about npm script deprecation', v => v.split(',')); @@ -38,6 +39,13 @@ program }); }); +program + .command('core:changelog') + .description('Builds changelog markdown') + .action(async cmd => { + await execTask(changelogTask)({}); + }); + program.parse(process.argv); if (program.depreciate && program.depreciate.length === 2) { diff --git a/scripts/cli/tasks/changelog.ts b/scripts/cli/tasks/changelog.ts new file mode 100644 index 00000000000..3e87ca888b0 --- /dev/null +++ b/scripts/cli/tasks/changelog.ts @@ -0,0 +1,34 @@ +import { Task, TaskRunner } from './task'; +import axios from 'axios'; +import issueRegex from 'issue-regex'; + +const githubGrafanaUrl = 'https://github.com/grafana/grafana'; + +interface ChangelogOptions {} + +const changelogTaskRunner: TaskRunner = async () => { + let client = axios.create({ + baseURL: 'https://api.github.com/repos/grafana/grafana', + timeout: 10000, + }); + + const res = await client.get('/issues?state=closed&labels=' + encodeURIComponent('add to changelog')); + let markdown = ''; + + for (const item of res.data) { + markdown += '* ' + item.title; + markdown += ` [#${item.number}](${githubGrafanaUrl}/issues/${item.number})`; + + for (const issue of item.body.match(issueRegex())) { + markdown += ` [#${issue}](${githubGrafanaUrl}/issues/${issue})`; + } + + markdown += '\n'; + } + + console.log(markdown); +}; + +export const changelogTask = new Task(); +changelogTask.setName('Changelog generator task'); +changelogTask.setRunner(changelogTaskRunner); diff --git a/yarn.lock b/yarn.lock index 3d97ef64374..4bfd7775564 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9929,6 +9929,11 @@ isstream@~0.1.2: resolved "https://registry.yarnpkg.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a" integrity sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo= +issue-regex@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/issue-regex/-/issue-regex-3.0.0.tgz#275c5dac460e7827819f749747baf686109695b7" + integrity sha512-KGkx4olfVCmESgFvImfiehUcY+WXnyVZ7uHKJO1eJWQr5QaAn9MSc0ejbCqCrBjafxwDxJ3cB5+dw8tQ8KZNzg== + istanbul-api@^1.3.1: version "1.3.7" resolved "https://registry.yarnpkg.com/istanbul-api/-/istanbul-api-1.3.7.tgz#a86c770d2b03e11e3f778cd7aedd82d2722092aa"