Skip to content

Add support for adding close label#135

Merged
hross merged 2 commits intoactions:mainfrom
mollyIV:feature/close-label
Sep 8, 2020
Merged

Add support for adding close label#135
hross merged 2 commits intoactions:mainfrom
mollyIV:feature/close-label

Conversation

@mollyIV
Copy link
Copy Markdown
Contributor

@mollyIV mollyIV commented Aug 4, 2020

Closes #134.

Description

This pull request is introducing two new params to the public interface:

close-issue-label:
    description: 'The label to apply when an issue is closed.'

close-pr-label:
    description: 'The label to apply when a pull request is closed.'

These are new labels, that can be applied when an issue / a pr is closed.

Testing

Unit Tests

Unfortunately I was not able to implement unit tests for this functionality due to the current limitations of IssueProcessor verification - we cannot verify how an issue / a pr has been affected by params like close-issue-message or stale-issue-label.

We could create a separate issue / pr to improve testing part. One of the idea could be using nock to mock the calls to the GitHub API. That would allow us for more complex verification of the modifications:

test('processing a stale issue will close it with close label when close-issue-label is set', async () => {
  const TestIssueList: Issue[] = [
    generateIssue(
      1,
      'A stale issue that should be closed',
      '2020-01-01T17:00:00Z',
      false,
      ['Stale']
    )
  ];

  const opts = {...DefaultProcessorOptions};
  opts.closeIssueLabel = 'Closed'

  const processor = new IssueProcessor(
    DefaultProcessorOptions,
    async p => (p == 1 ? TestIssueList : []),
    async (num, dt) => [],
    async (issue, label) => new Date().toDateString()
  );

  // 🔨  GitHub API mocking with nock 

  // process our fake issue list
  await processor.processIssues(1);

  // 🔨  verify if the label `Closed` is added to the issue
});

Let me please know what you think 😊

Manual testing

name: Closing stale issues
on:
  schedule:
  - cron: "0 0 * * *"

jobs:
  stale:
    runs-on: ubuntu-latest
    steps:
    - uses: mollyIV/stale@feature/close-label
      with:
        repo-token: ${{ secrets.BOT_GITHUB_TOKEN }}
        days-before-stale: 1
        days-before-close: 1
        stale-issue-message: > 
          There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.
          
          Please make sure to update to the latest `fastlane` version and check if that solves the issue. Let us know if that works for you by adding a comment :+1:
          
          Friendly reminder: contributions are always welcome! Check out [CONTRIBUTING.md](https://github.com/fastlane/fastlane/blob/master/CONTRIBUTING.md) for more information on how to help with `fastlane` and feel free to tackle this issue yourself :muscle:
        stale-issue-label: 'status: waiting-for-reply'
        close-issue-message: >
          This issue will be auto-closed because there hasn't been any activity for a few months. Feel free to [open a new one](https://github.com/fastlane/fastlane/issues/new) if you still experience this problem 👍
        stale-pr-label: 'status: needs-attention'
        skip-stale-pr-message: true
        stale-pr-message: 'Stale'
        close-pr-label: 'issue-status: auto-closed'
        close-issue-label: 'pr-status: auto-closed'

Screenshot 2020-08-11 at 08 28 10

Screenshot 2020-08-11 at 08 27 53

I have used my personal token, so the comments come from my user.

🎊

@mollyIV mollyIV marked this pull request as ready for review August 11, 2020 06:30
@hross
Copy link
Copy Markdown
Contributor

hross commented Aug 28, 2020

@mollyIV this is great. If you rebase and recreate dist for this change I will merge it and release it (sorry it took me so long to review)

@hross hross added the enhancement New feature or request label Aug 28, 2020
@hross hross self-requested a review August 28, 2020 10:18
# Conflicts:
#	dist/index.js
@mollyIV
Copy link
Copy Markdown
Contributor Author

mollyIV commented Sep 8, 2020

Hello @hross 👋

Thank you for the code review 🙇 I have merged the main into this branch and recreated dist. Sorry it took quite long.
Thanks!

@hross hross merged commit 13b324e into actions:main Sep 8, 2020
@hross
Copy link
Copy Markdown
Contributor

hross commented Sep 8, 2020

I will recreate a new release this Friday and include this PR.

@mollyIV mollyIV deleted the feature/close-label branch December 2, 2020 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for adding close label

2 participants