changelog.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { Task, TaskRunner } from './task';
  2. import axios from 'axios';
  3. const githubGrafanaUrl = 'https://github.com/grafana/grafana';
  4. interface ChangelogOptions {
  5. milestone: string;
  6. }
  7. const changelogTaskRunner: TaskRunner<ChangelogOptions> = async ({ milestone }) => {
  8. let client = axios.create({
  9. baseURL: 'https://api.github.com/repos/grafana/grafana',
  10. timeout: 10000,
  11. });
  12. const res = await client.get('/issues', {
  13. params: {
  14. state: 'closed',
  15. labels: 'add to changelog',
  16. },
  17. });
  18. let markdown = '';
  19. for (const item of res.data) {
  20. if (!item.milestone) {
  21. console.log('Item missing milestone', item.number);
  22. continue;
  23. }
  24. // For some reason I could not get the github api to filter on milestone and label
  25. // So doing this filter here
  26. if (item.milestone.title !== milestone) {
  27. continue;
  28. }
  29. markdown += '* ' + item.title + '.';
  30. markdown += ` [#${item.number}](${githubGrafanaUrl}/pull/${item.number})`;
  31. markdown += `, [@${item.user.login}](${item.user.html_url})`;
  32. markdown += '\n';
  33. }
  34. console.log(markdown);
  35. };
  36. export const changelogTask = new Task<ChangelogOptions>();
  37. changelogTask.setName('Changelog generator task');
  38. changelogTask.setRunner(changelogTaskRunner);