mheap / github-action-required-labels

Fail the build if/unless a certain combination of labels are applied to a pull request
MIT License
99 stars 23 forks source link

Customizable comments? #43

Closed mathomp4 closed 1 year ago

mathomp4 commented 1 year ago

This is more of a question/feature request than an issue, but I thought I'd ask.

Recently I transitioned my repos from an old Heroku label enforcer to this very cool GitHub Action. One of the things I loved about it was the fact that it can make a comment when something goes wrong. Nice.

However, I was wondering how hard it would be to make that comment customizable? I ask because in our systems we have two different types of labels. One set are required to merge, but we use a different set of labels to "block" the PR (because someone needs to approve, or the PR in question depends on another PR, etc.). You can see the comments made by both of these here in my test repo.

Now it does work and the comment feature is MUCH nicer than what we had before (which was people asking me "Why is my PR not able to merge?"). But it might be easier for them to understand with a comment like:

This PR is being prevented from merging because you have not added one of our required labels: A, B, C. Please add one of these.

or:

This PR is being prevented from merging because you have added one of our blocking labels: D, E, F. You'll need to remove it before this PR can be merged.

Of course, I don't know how these GitHub Actions even work, so if something like this takes more than like 5 minutes of effort, probably not worth it! 😄

mheap commented 1 year ago

Started looking in to this today. Rough notes for what it needs:

function tmpl(t, o) {
  return t.replace(/\{\{\s*(.*?)\s*\}\}/g, function (item, param) {
    return o[param];
  });
}

const comment = core.getInput("comment");
const errorMessage = tmpl(comment, {
    mode,
    allowed: allowedLabels.join(", "),
    applied: appliedLabels.join(", "),
});