changelog.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import _ from 'lodash';
  2. import { Task, TaskRunner } from './task';
  3. import axios from 'axios';
  4. const githubGrafanaUrl = 'https://github.com/grafana/grafana';
  5. interface ChangelogOptions {
  6. milestone: string;
  7. }
  8. const changelogTaskRunner: TaskRunner<ChangelogOptions> = async ({ milestone }) => {
  9. let client = axios.create({
  10. baseURL: 'https://api.github.com/repos/grafana/grafana',
  11. timeout: 10000,
  12. });
  13. const res = await client.get('/issues', {
  14. params: {
  15. state: 'closed',
  16. labels: 'add to changelog',
  17. },
  18. });
  19. const issues = res.data.filter(item => {
  20. if (!item.milestone) {
  21. console.log('Item missing milestone', item.number);
  22. return false;
  23. }
  24. return item.milestone.title === milestone;
  25. });
  26. const bugs = _.sortBy(
  27. issues.filter(item => {
  28. if (item.title.match(/fix|fixes/i)) {
  29. return true;
  30. }
  31. if (item.labels.find(label => label.name === 'type/bug')) {
  32. return true;
  33. }
  34. return false;
  35. }),
  36. 'title'
  37. );
  38. const notBugs = _.sortBy(res.data.filter(item => !bugs.find(bug => bug === item)), 'title');
  39. let markdown = '### Features / Enhancements\n';
  40. for (const item of notBugs) {
  41. markdown += getMarkdownLineForIssue(item);
  42. }
  43. markdown += '\n### Bug Fixes\n';
  44. for (const item of bugs) {
  45. markdown += getMarkdownLineForIssue(item);
  46. }
  47. console.log(markdown);
  48. };
  49. function getMarkdownLineForIssue(item: any) {
  50. let markdown = '';
  51. let title = item.title.replace(/^([^:]*)/, (match, g1) => {
  52. return `**${g1}**`;
  53. });
  54. markdown += '* ' + title + '.';
  55. markdown += ` [#${item.number}](${githubGrafanaUrl}/pull/${item.number})`;
  56. markdown += `, [@${item.user.login}](${item.user.html_url})`;
  57. markdown += '\n';
  58. return markdown;
  59. }
  60. export const changelogTask = new Task<ChangelogOptions>();
  61. changelogTask.setName('Changelog generator task');
  62. changelogTask.setRunner(changelogTaskRunner);