Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assigns labels based on branch names #203

Merged
merged 119 commits into from
May 24, 2023
Merged

Conversation

joshdales
Copy link
Contributor

@joshdales joshdales commented Aug 7, 2021

Description:
Assign a label based on the branch name.

Depending on your branch name you may want to apply different labels based on the purpose of the branch. You can specify the base-branch or the head-branch that you wish to apply the labels based on. The config options for the branch can be listed as a string or an array of strings.

Puts all the branch matching, and changed files logic in their own files with some unit tests, and should hopefully create a good base for expanding with further options for matching options.

Related issues:

Check list:

  • Mark if documentation changes are required.
  • Mark if tests were added or updated to cover the changes.

Breaking Changes:
Changes the config structure so that the any and all now have more options their original values are now under the changed-files key:

label:
  - any: 
    - changed-files: ['list', 'of', 'globs']
    - base-branch: ['list', 'of', 'regexps']
    - head-branch: ['list', 'of', 'regexps']
  - all:
    - changed-files: ['list', 'of', 'globs']
    - base-branch: ['list', 'of', 'regexps']
    - head-branch: ['list', 'of', 'regexps']

If you omit a top level key it will default to any:

label:
  - changed-files: ['list', 'of', 'globs']
  - base-branch: ['list', 'of', 'regexps']
  - head-branch: ['list', 'of', 'regexps']

@joshdales joshdales requested a review from a team as a code owner August 7, 2021 19:49
@amiel
Copy link
Contributor

amiel commented Sep 15, 2021

FYI: I found that this wasn't working for me as expected. I got it working for me in joshdales#1. I didn't spend much time writing up any context, partly because this PR doesn't have any response, so I'm not sure if anyone is planning to take the time to review this. I'd be happy to communicate more about it if there's interest.

EDIT: Updated PR reference.

@joshdales
Copy link
Contributor Author

@amiel If it's not working properly I'm still interested so would appreciate any information you can give 😄

@amiel
Copy link
Contributor

amiel commented Sep 15, 2021

Hi @joshdales. I just realized that I referenced the wrong pull request in my last comment. I've edited it to reference the one I meant to reference: joshdales#1.

The problem I ran in to was that github.context.ref was producing something like refs/pull/23/head, which would not match my branch names like feature/foo.

Using github.context.payload.pull_request.head.ref resolves this for me and uses the branch name that I actually want to match on. I don't have a lot of experience with github actions, but I found this object path here: https://github.com/TimonVS/pr-labeler-action/blob/master/src/action.ts#L25.

@amiel
Copy link
Contributor

amiel commented Sep 15, 2021

I also considered updating your changes to support a list of branch patterns, just like the way lists of files are supported. However, I got it working by using the glob matching and I added a test to demonstrate that. This took me a little while to figure out because the minimatch documentation shows an example with (bar|foo), but I needed to use the glob syntax ({bar,foo}) instead.

amiel and others added 2 commits September 16, 2021 12:22
Safer access of pull_request data.

Co-authored-by: Josh Dales <30500472+joshdales@users.noreply.github.com>
@joshdales
Copy link
Contributor Author

@amiel took your suggestion and I've updated this PR to support a list of branch arguments as well 👍

@amiel
Copy link
Contributor

amiel commented Sep 30, 2021

@joshdales Awesome! I'll pull those changes upstream too since we are pinned to our branch until this gets actually released.

@david-heward-unmind
Copy link

Be cool to get this feature shipped. I'd selfishly find it useful.

@MaksimZhukov
Copy link
Contributor

Hi @joshdales and @lucacome! Sorry for the delay in responding!

We had a discussion within the team and we decided to follow your recommendations. Let's update the any selector to match any file against any glob pattern. We will release these changes as a new beta version so that users can test them and share their feedback. If they are satisfied with the new approach, we will release a stable version.

@joshdales please revert your recent changes. Sorry for going back and forth, and thank you for your time and efforts!

@joshdales
Copy link
Contributor Author

@MaksimZhukov Changes reverted 👍

Copy link
Contributor

@MaksimZhukov MaksimZhukov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @joshdales for the updates! Everything looks great, I left some minor comments

src/labeler.ts Outdated Show resolved Hide resolved
src/labeler.ts Outdated Show resolved Hide resolved
src/labeler.ts Outdated Show resolved Hide resolved
src/branch.ts Outdated Show resolved Hide resolved
__tests__/changedFiles.test.ts Outdated Show resolved Hide resolved
@lucacome
Copy link

I really didn't want to add another comment, but...seems like something is not working... 😭

with the same config as usual:

tests:
  - any:
      - head-branch: ['^tests/', '^test/']
      - changed-files: ['tests/**/*', 'perf-tests/**/*']
  - all:
      - changed-files: ['!tests/requirements.txt', '!perf-tests/requirements.txt']

I get

##[debug]processing tests
##[debug] checking config {"any":[{"headBranch":["^tests/","^test/"]},{"changedFiles":["tests/**/*","perf-tests/**/*"]}]}
##[debug]  checking "any" patterns
##[debug]   checking "branch" pattern against deps/foo
##[debug]    - /^tests\//
##[debug]    /^tests\// did not match
##[debug]    - /^test\//
##[debug]    /^test\// did not match
##[debug]   "branch" patterns did not match against deps/foo
##[debug]    matching patterns against file README.md
##[debug]     - tests/**/*
##[debug]     - perf-tests/**/*
##[debug]    no patterns matched
##[debug]    matching patterns against file tests/bar
##[debug]     - tests/**/*
##[debug]    tests/**/* matched
##[debug]   "any" patterns matched against tests/bar
##[debug] checking config {"all":[{"changedFiles":["!tests/requirements.txt","!perf-tests/requirements.txt"]}]}
##[debug]  checking "all" patterns
##[debug]  no "all" patterns to check

and the tests label is removed even tho "any" patterns matched against tests/bar.
It seems to me that is something with the "all" pattern from no "all" patterns to check.

@joshdales
Copy link
Contributor Author

@lucacome I've pushed up a fix for this (and added a extra test based on your config so hopefully I don't accidentally break it again 🙈).

Thanks for your support with the testing comments - it has been much appreciated 🙏

@MaksimZhukov MaksimZhukov changed the base branch from main to v5.0.0-beta.1 May 23, 2023 17:14
@MaksimZhukov MaksimZhukov merged commit e1fcf6f into actions:v5.0.0-beta.1 May 24, 2023
@MaksimZhukov
Copy link
Contributor

Hello everyone!
We released the new version of the action that includes these changes. For more information, see the release notes.

@joshdales thanks for working on this PR, for your time and contribution! It was a pleasure to work with you!
Thank you all for your comments and patience!

lucacome added a commit to lucacome/nginx-kubernetes-gateway that referenced this pull request May 31, 2023
actions/labeler#203 was finally merged and
actions/labeler created a pre-release with the changes.

This updates the version of the action to use the official
actions/labeler.
It also updates labeler.yml with the new config format and adds missing change
label.
lucacome added a commit to nginxinc/nginx-gateway-fabric that referenced this pull request May 31, 2023
actions/labeler#203 was finally merged and
actions/labeler created a pre-release with the changes.

This updates the version of the action to use the official
actions/labeler.
It also updates labeler.yml with the new config format and adds missing change
label.
sp3nx0r referenced this pull request in sp3nx0r/homelab Dec 24, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [actions/labeler](https://togithub.com/actions/labeler) | action |
major | `v4.3.0` -> `v5.0.0` |

---

### Release Notes

<details>
<summary>actions/labeler (actions/labeler)</summary>

### [`v5.0.0`](https://togithub.com/actions/labeler/releases/tag/v5.0.0)

[Compare
Source](https://togithub.com/actions/labeler/compare/v4.3.0...v5.0.0)

#### What's Changed

This release contains the following breaking changes:

1. The ability to apply labels based on the names of base and/or head
branches was added
([#&#8203;186](https://togithub.com/actions/labeler/issues/186) and
[#&#8203;54](https://togithub.com/actions/labeler/issues/54)). The match
object for changed files was expanded with new combinations in order to
make it more intuitive and flexible
([#&#8203;423](https://togithub.com/actions/labeler/issues/423) and
[#&#8203;101](https://togithub.com/actions/labeler/issues/101)). As a
result, the configuration file structure was significantly redesigned
and is not compatible with the structure of the previous version. Please
read the [action
documentation](https://togithub.com/actions/labeler/tree/main#pull-request-labeler)
to find out how to adapt your configuration files for use with the new
action version.

2. The bug related to the `sync-labels` input was fixed
([#&#8203;112](https://togithub.com/actions/labeler/issues/112)). Now
the input value is read correctly.

3. By default, `dot` input is set to `true`. Now, paths starting with a
dot (e.g. `.github`) are matched by default.

4. Version 5 of this action updated the [runtime to Node.js
20](https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runs-for-javascript-actions).
All scripts are now run with Node.js 20 instead of Node.js 16 and are
affected by any breaking changes between Node.js 16 and 20.

For more information, please read the [action
documentation](https://togithub.com/actions/labeler/tree/main#pull-request-labeler).

#### New Contributors

- [@&#8203;joshdales](https://togithub.com/joshdales) made their first
contribution in
[https://github.com/actions/labeler/pull/203](https://togithub.com/actions/labeler/pull/203)
- [@&#8203;dusan-trickovic](https://togithub.com/dusan-trickovic) made
their first contribution in
[https://github.com/actions/labeler/pull/626](https://togithub.com/actions/labeler/pull/626)
- [@&#8203;sungh0lim](https://togithub.com/sungh0lim) made their first
contribution in
[https://github.com/actions/labeler/pull/630](https://togithub.com/actions/labeler/pull/630)
- [@&#8203;TrianguloY](https://togithub.com/TrianguloY) made their first
contribution in
[https://github.com/actions/labeler/pull/629](https://togithub.com/actions/labeler/pull/629)

**Full Changelog**:
actions/labeler@v4...v5.0.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "on saturday" (UTC), Automerge - At
any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/sp3nx0r/homelab).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy44Ny4yIiwidXBkYXRlZEluVmVyIjoiMzcuODcuMiIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Apply labels based on branch name Label PR based on base branch