diff --git a/.github/workflows/issue_bot.yml b/.github/workflows/issue_bot.yml index 3e5b2a4dcfa7..32e5effab34b 100644 --- a/.github/workflows/issue_bot.yml +++ b/.github/workflows/issue_bot.yml @@ -51,6 +51,19 @@ jobs: `Thanks for your report! The ${component} implementation has moved to https://github.com/apache/${repo}.\n\n` + `This issue has been closed automatically - please open a new issue there.`; + let component_to_prefix = (component) => { + const prefix_overrides = { + "Continuous Integration": "CI", + "Developer Tools": "Dev", + "Documentation": "Docs", + }; + return prefix_overrides[component] || component; + }; + + let title_has_prefix = (title, prefix) => { + return title.includes(`[${prefix}]`); + }; + let split_body = context.payload.issue.body.split('### Component(s)'); if (split_body.length != 2) throw new Error('No components found!'); @@ -104,6 +117,30 @@ jobs: if (component_labels.length == 0) throw new Error('No components found!'); + let component_prefixes = component_labels.map( + label => component_to_prefix(label.substring("Component: ".length)) + ); + + let issue_title = context.payload.issue.title.trimStart(); + + let missing_prefixes = component_prefixes.filter( + prefix => !title_has_prefix(issue_title, prefix) + ); + + let missing_title_prefix = missing_prefixes + .map(prefix => `[${prefix}]`) + .join(""); + + if (missing_title_prefix) { + let title_separator = issue_title.startsWith("[") ? "" : " "; + await github.rest.issues.update({ + "owner": context.repo.owner, + "repo": context.repo.repo, + "issue_number": context.payload.issue.number, + "title": missing_title_prefix + title_separator + issue_title, + }); + } + await github.rest.issues.setLabels({ "owner": context.repo.owner, "repo": context.repo.repo,