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

feat: Support discussion event #487

Merged
merged 33 commits into from
Aug 15, 2021
Merged

feat: Support discussion event #487

merged 33 commits into from
Aug 15, 2021

Conversation

peaceiris
Copy link
Owner

@peaceiris peaceiris commented Aug 11, 2021

Close #444

This feature needs a personal access token as well as #485.

References

Test this implementation

  • Add event on.discussion
  • Use 70a7e5a7341326e42a96580b0134a4054c47e2a8

Workflow

name: Label Commenter

on:
  issues:
    types:
      - labeled
      - unlabeled
  pull_request_target:
    types:
      - labeled
      - unlabeled
  discussion:
    types:
      - labeled
      - unlabeled

jobs:
  comment:
    runs-on: ubuntu-20.04
    timeout-minutes: 1
    steps:
      - uses: actions/checkout@v2

      - name: Label Commenter
        uses: peaceiris/actions-label-commenter@70a7e5a7341326e42a96580b0134a4054c47e2a8
        env:
          RUNNER_DEBUG: 1
        with:
          github_token: ${{ secrets.GH_PAT }}

Config

labels:
  - name: proposal
    labeled:
      discussion:
        body: Thank you @{{ author }} for suggesting this.

  - name: locked (spam)
    labeled:
      discussion:
        body: |
          This {{ eventName }} \#{{ number }} has been **LOCKED** with the label {{ labelName }}!

          Please do not spam messages on this project. You may get blocked from this repository for doing so.
        locking: lock
        lock_reason: spam
        answer: true

  - name: locked (heated)
    labeled:
      discussion:
        body: |
          This discussion has been **LOCKED** because of heated conversation!

          We appreciate exciting conversations, as long as they won't become too aggressive and/or emotional.
        locking: lock
        lock_reason: too heated
    unlabeled:
      discussion:
        body: |
          This discussion has been unlocked now.
        locking: unlock

@codecov
Copy link

codecov bot commented Aug 11, 2021

Codecov Report

Merging #487 (315e68d) into main (49c789d) will increase coverage by 6.83%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #487      +/-   ##
==========================================
+ Coverage   87.90%   94.73%   +6.83%     
==========================================
  Files           6        5       -1     
  Lines         124      133       +9     
  Branches       22       27       +5     
==========================================
+ Hits          109      126      +17     
+ Misses         15        7       -8     
Impacted Files Coverage Δ
src/classes/action-processor.ts 96.00% <100.00%> (+12.21%) ⬆️
src/classes/comment.ts 91.07% <100.00%> (+1.27%) ⬆️
src/logger.ts

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ee8ef31...315e68d. Read the comment docs.

@peaceiris peaceiris force-pushed the feat-support-discussion branch 3 times, most recently from 2555b36 to 1ee60b6 Compare August 13, 2021 01:17
@Andre601
Copy link
Contributor

The action seems to work fine, see Readme-Workflows/recent-activity#96 for the result and https://github.com/Readme-Workflows/recent-activity/actions/runs/1126154000 for the execution.

On another note do I have two separate suggestions I want to propose, from which one is related to discussions.

1) Mark the bot's reply as answer

If possible should there be perhaps a setting to not only respond to a discussion, but to also mark this comment as the answer, if the category allows such a thing.
This could have a lot of uses for commonly asked questions, where you could through labels give canned responses and select them as answers right afterwards.

2) More generic placeholders for specific values

Right now do I need to use {{ issue.user.login }}, {{ pull_request.user.login }} or {{ discussion.user.login }} to achieve the same thing for issues, PRs and discussions respectively, which is getting the username of the person that created the issue, PR and/or discussion.

This is somewhat annoying to have and I would like to propose some more generic/common placeholders to use, which would use different keys depending on the type.

  • {{ author }} - Name of who created the Issue, PR or Discussion.
  • {{ labeler }} - Name of who labeled the Issue, PR or Discussion.
  • {{ id }} - The id of the Issue, PR or Discussion. (Maybe? Can't think of a good use-case here)

@peaceiris
Copy link
Owner Author

Thank you for the feedback!

About 1: It is difficult to figure it out which comment is the best answer. The latest comment is not always that.

About 2: I have added this to #449.

@Andre601
Copy link
Contributor

About 1: It is difficult to figure it out which comment is the best answer. The latest comment is not always that.

I mean more like:

  • You label the discussion
  • Bot responds with canned response
  • Bot markets own response (The canned response) as answer.

I don't ask for a system that selects the best or most recent one (before the bot) but that the bot would select its own response as answer, if that is doable through the GitHub API.

@peaceiris peaceiris force-pushed the feat-support-discussion branch 2 times, most recently from a432c66 to 17eb590 Compare August 13, 2021 03:54
@peaceiris
Copy link
Owner Author

5da68592ce3ed65f0be17ef9eddabe0fa000fc28 supports the following placeholders now.

  • author
  • labeler
  • eventName
  • number
  • labelName
labels:
  - name: proposal
    labeled:
      issue:
        body: &proposal_body Thank you @{{ author }} for suggesting this.
      discussion:
        body: *proposal_body

  - name: locked (spam)
    labeled:
      issue:
        body: &locked_spam_body |
          This {{ eventName }} \#{{ number }} has been **LOCKED** with the label {{ labelName }}!

          Please do not spam messages on this project. You may get blocked from this repository for doing so.
        action: close
        locking: lock
        lock_reason: spam
      pr:
        body: *locked_spam_body
        action: close
        locking: lock
        lock_reason: spam
      discussion:
        body: *locked_spam_body
        locking: lock
        lock_reason: spam

@peaceiris
Copy link
Owner Author

3dcfc91b6291a15f1d409417f392aeea6db1a4fb supports discussion.answer: true now.

@peaceiris
Copy link
Owner Author

439d9ad8e37a55809451cd7a938fe2b6bd9dc29e fixes {{ eventName }} as follows:

  • if on.issues, returns issue
  • if on.(pull_request|pull_request_target), returns pull request
  • if on.discussion, returns discussion

@ayamebot ayamebot added the cicd label Aug 15, 2021
@peaceiris peaceiris marked this pull request as ready for review August 15, 2021 01:26
@peaceiris peaceiris merged commit 74cbdae into main Aug 15, 2021
@peaceiris peaceiris deleted the feat-support-discussion branch August 15, 2021 01:27
@peaceiris
Copy link
Owner Author

peaceiris commented Oct 2, 2021

This feature works without a personal access token now, but #485 still requires that.

name: Label Commenter

on:
  issues:
    types: [labeled, unlabeled]
  pull_request_target:
    types: [labeled, unlabeled]
  discussion:
    types: [labeled, unlabeled]

permissions:
  contents: read
  issues: write
  pull-requests: write
  discussions: write

jobs:
  comment:
    runs-on: ubuntu-20.04
    timeout-minutes: 1
    steps:
      - name: Label Commenter
        uses: peaceiris/actions-label-commenter@c2d00660c86f2b9ed0fb35b372c451558eba85b3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

proposal: Discussion support
3 participants