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: Toggle pull-request draft status #485

Merged
merged 47 commits into from
Aug 11, 2021
Merged

feat: Toggle pull-request draft status #485

merged 47 commits into from
Aug 11, 2021

Conversation

peaceiris
Copy link
Owner

@peaceiris peaceiris commented Aug 8, 2021

Close #436

Overview

My proposal about a REST API to toggle pull-request draft status (pulls.update: Change pull-request draft status · Issue #69 · octokit/rest.js) has been rejected since the GitHub API v4 (GraphQL API) has the ability to do that.

Unfortunately, an auto-generated access token called GITHUB_TOKEN seems not to have full control permission of the GraphQL API. We got the error Resource not accessible by integration with the GitHub API v4 and GITHUB_TOKEN. This problem may be related to the following thread.

This pull-request uses a personal access token with a public_repo scope (for a public repository) as a workaround.

References

Test This Implementation

Workflow

Provide a personal access token with a public_repo scope (for a public repository) as the GH_PAT secret.

name: Label Commenter

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

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

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

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

Label Commenter Config

Add draft: true or draft: false to a pr field.

labels:
  - name: invalid
    labeled:
      pr:
        body: Thank you @{{ pull_request.user.login }} for suggesting this. Please follow the pull request templates.
        action: close
        draft: true

  - name: locked (heated)
    labeled:
      pr:
        body: |
          This pull-request 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
        draft: true
    unlabeled:
      pr:
        body: |
          This pull-request has been unlocked now.
        locking: unlock
        draft: false

@codecov
Copy link

codecov bot commented Aug 8, 2021

Codecov Report

Merging #485 (aecdba5) into main (1c813ca) will decrease coverage by 4.40%.
The diff coverage is 80.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #485      +/-   ##
==========================================
- Coverage   92.30%   87.90%   -4.41%     
==========================================
  Files           6        6              
  Lines         117      124       +7     
  Branches       18       22       +4     
==========================================
+ Hits          108      109       +1     
- Misses          9       15       +6     
Impacted Files Coverage Δ
src/classes/action-processor.ts 83.78% <60.00%> (-4.10%) ⬇️
src/classes/comment.ts 89.79% <100.00%> (+0.21%) ⬆️
src/logger.ts 63.63% <100.00%> (-36.37%) ⬇️

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 1c813ca...aecdba5. Read the comment docs.

@peaceiris
Copy link
Owner Author

Thank you for the super quick try! Please use 06a7f624808ccde484c21bf2bc8fdbdf71a19339.

@Andre601
Copy link
Contributor

Andre601 commented Aug 9, 2021

It seems to work, but the downside is, that the user account of the PAT is used for the comment:
image

@peaceiris
Copy link
Owner Author

Yes. I totally agree with you. We have no way to avoid that behavior with a pat.

I think GITHUB_TOKEN is better than a personal access token. So, I am going to post a suggestion about permission improvement about GITHUB_TOKEN with GraphQL API to GitHub Community later.

@Andre601
Copy link
Contributor

Andre601 commented Aug 9, 2021

Yes. I totally agree with you. We have no way to avoid that behavior with a pat.

I think GITHUB_TOKEN is better than a personal access token. So, I am going to post a suggestion about permission improvement about GITHUB_TOKEN with GraphQL API to GitHub Community later.

https://github.51.almunity/t/allow-the-github-token-to-also-have-rights-for-converting-prs-to-draft-or-vice-versa/194555

You're welcome. (Comment with anything I missed to mention or explain)

@Andre601
Copy link
Contributor

I for now have a dedicated account for the Repository where I want to use the draft feature and it seems to work fine.
image

@peaceiris
Copy link
Owner Author

Good!

@peaceiris
Copy link
Owner Author

peaceiris commented Aug 11, 2021

This will be merged and released as the v1.11.0 with other new features. Watch v2.0.0 Milestone. We can continue to use 06a7f624808ccde484c21bf2bc8fdbdf71a19339 until the v2.0.0 will be published.

@peaceiris peaceiris marked this pull request as ready for review August 11, 2021 00:53
@peaceiris peaceiris merged commit 2756d58 into main Aug 11, 2021
@peaceiris peaceiris deleted the feat-draft branch August 11, 2021 00:54
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: Add action to turn PR into Draft and vice-versa
2 participants