Skip to content

Commit

Permalink
GH: Fix missing issues (using pagination), add annotations based on l…
Browse files Browse the repository at this point in the history
…abels

Signed-off-by: Javier Romero <[email protected]>
  • Loading branch information
jromero committed May 27, 2020
1 parent ab7a2d7 commit 2cf2c34
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions .github/workflows/build/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,21 @@ module.exports = async ({core, github}) => {

const typeLabelPrefix = 'type/';
const typeLabelsMap = {
"features": typeLabelPrefix + "enhancement",
"fixes": typeLabelPrefix + "bug",
"Features": typeLabelPrefix + "enhancement",
"Fixes": typeLabelPrefix + "bug",
};

return await github.search.issuesAndPullRequests({
// Map of annotations to be added to issue per label.
const annotationLabelsMap = {
"experimental": "experimental",
"breaking": "breaking-change",
};

return await github.paginate("GET /search/issues", {
q: `repo:${repository} is:pr state:closed milestone:${milestone}`,
}).then(({data}) => {
}).then((items) => {
// group issues by type label
return data.items.reduce((groupedMap, issue) => {
return items.reduce((groupedMap, issue) => {
let typeLabels = issue.labels.filter(label => {
return label.name.startsWith(typeLabelPrefix);
}).map(label => label.name);
Expand All @@ -35,13 +41,26 @@ module.exports = async ({core, github}) => {
let output = "";

for (let key in typeLabelsMap) {
output += `## ${key.toUpperCase()}\n\n`;
output += `## ${key}\n\n`;
(groupedIssues[typeLabelsMap[key]] || []).forEach(issue => {
output += `* ${issue.title} (#${issue.number})\n`;
let annotations = [];
issue.labels.forEach(label => {
for (const annotation in annotationLabelsMap) {
if (annotationLabelsMap[annotation] === label.name) {
annotations.push(annotation);
}
}
});

if (annotations.length !== 0) {
output += `* ${issue.title} [${annotations.join(", ")}] (#${issue.number})\n`;
} else {
output += `* ${issue.title} (#${issue.number})\n`;
}
});
output += `\n`;
}

output = output.trim();

fs.writeFile("changelog.md", output, function (err) {
Expand Down

0 comments on commit 2cf2c34

Please sign in to comment.