I try to implement an example of changing label automatically after pull request is merged through Github Action
I also defined token from secret assigning to github-token
I have a problem in Assign Label to Issue.
It throws the error shown below
Run actions/github-script@v4
with:
github-token: ***
script: github.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: null,
labels: ['done']
})
debug: false
user-agent: actions/github-script
result-encoding: json
(node:1863) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
RequestError [HttpError]: Not Found
at /home/runner/work/_actions/actions/github-script/v4/dist/index.js:4662:21
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
status: 404,
response: {
Error: Unhandled error: HttpError: Not Found
url: 'https://api.github.username/repos/u/repo_name/issues//labels',
status: 404,
headers: {
'access-control-allow-origin': '*',
'access-control-expose-headers': 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset',
connection: 'close',
'content-encoding': 'gzip',
'content-security-policy': "default-src 'none'",
'content-type': 'application/json; charset=utf-8',
date: 'Mon, 27 May 2024 20:45:08 GMT',
'referrer-policy': 'origin-when-cross-origin, strict-origin-when-cross-origin',
server: 'GitHub.com',
'strict-transport-security': 'max-age=31536000; includeSubdomains; preload',
'transfer-encoding': 'chunked',
vary: 'Accept-Encoding, Accept, X-Requested-With',
'x-accepted-oauth-scopes': 'repo',
'x-content-type-options': 'nosniff',
'x-frame-options': 'deny',
'x-github-api-version-selected': '2022-11-28',
'x-github-media-type': 'github.v3',
'x-github-request-id': '2383:1B5AF2:41333F0:7101B83:6654F0D4',
'x-oauth-scopes': 'admin:enterprise, admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, admin:ssh_signing_key, audit_log, codespace, copilot, delete:packages, delete_repo, gist, notifications, project, repo, user, workflow, write:discussion, write:packages',
'x-ratelimit-limit': '5000',
'x-ratelimit-remaining': '4992',
'x-ratelimit-reset': '1716843733',
'x-ratelimit-resource': 'core',
'x-ratelimit-used': '8',
'x-xss-protection': '0'
},
data: {
message: 'Not Found',
documentation_url: 'https://docs.github.com/rest'
}
},
request: {
method: 'POST',
url: 'https://api.github.username/repos/u/repo_name/issues//labels',
headers: {
accept: 'application/vnd.github.-preview+json',
'user-agent': 'actions/github-script octokit-core.js/3.5.1 Node.js/16.20.2 (linux; x64)',
authorization: 'token [REDACTED]',
'content-type': 'application/json; charset=utf-8'
},
body: '{"labels":["done"]}',
request: { agent: [Agent], hook: [Function: bound bound register] }
}
How can I fix it?
Here is the code snippet shown below
name: Assign Label on Merge
on:
pull_request:
types: [closed]
jobs:
assign-label-on-merge:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- name: Check out the code
uses: actions/checkout@v2
- name: Assign Label to PR
uses: actions/github-script@v4
with:
github-token: ${{ secrets.CRM_PULL_REQUEST_TOKEN }}
script: |
github.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: ['done']
})
- name: Remove 'development' Label from PR
uses: actions/github-script@v4
with:
github-token: ${{ secrets.CRM_PULL_REQUEST_TOKEN }}
script: |
github.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
name: 'development'
})
- name: Find Connected Issue
id: find_issue
run: |
ISSUE_NUMBER=$(jq --raw-output .issue.number $GITHUB_EVENT_PATH)
echo "issue_number=$ISSUE_NUMBER" >> $GITHUB_ENV
if: github.event.pull_request.merged && github.event.pull_request.head.repo != github.event.pull_request.base.repo
- name: Assign Label to Issue
if: steps.find_issue.outputs.issue_number
uses: actions/github-script@v4
with:
github-token: ${{ secrets.CRM_PULL_REQUEST_TOKEN }}
script: |
github.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ env.issue_number }},
labels: ['done']
})
- name: Remove 'development' Label from Issue
if: steps.find_issue.outputs.issue_number
uses: actions/github-script@v4
with:
github-token: ${{ secrets.CRM_PULL_REQUEST_TOKEN }}
script: |
github.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ env.issue_number }},
name: 'development'
})
I try to implement an example of changing label automatically after pull request is merged through Github Action
I also defined token from secret assigning to github-token
I have a problem in Assign Label to Issue.
It throws the error shown below
Run actions/github-script@v4
with:
github-token: ***
script: github.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: null,
labels: ['done']
})
debug: false
user-agent: actions/github-script
result-encoding: json
(node:1863) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
RequestError [HttpError]: Not Found
at /home/runner/work/_actions/actions/github-script/v4/dist/index.js:4662:21
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
status: 404,
response: {
Error: Unhandled error: HttpError: Not Found
url: 'https://api.github.username/repos/u/repo_name/issues//labels',
status: 404,
headers: {
'access-control-allow-origin': '*',
'access-control-expose-headers': 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset',
connection: 'close',
'content-encoding': 'gzip',
'content-security-policy': "default-src 'none'",
'content-type': 'application/json; charset=utf-8',
date: 'Mon, 27 May 2024 20:45:08 GMT',
'referrer-policy': 'origin-when-cross-origin, strict-origin-when-cross-origin',
server: 'GitHub.com',
'strict-transport-security': 'max-age=31536000; includeSubdomains; preload',
'transfer-encoding': 'chunked',
vary: 'Accept-Encoding, Accept, X-Requested-With',
'x-accepted-oauth-scopes': 'repo',
'x-content-type-options': 'nosniff',
'x-frame-options': 'deny',
'x-github-api-version-selected': '2022-11-28',
'x-github-media-type': 'github.v3',
'x-github-request-id': '2383:1B5AF2:41333F0:7101B83:6654F0D4',
'x-oauth-scopes': 'admin:enterprise, admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, admin:ssh_signing_key, audit_log, codespace, copilot, delete:packages, delete_repo, gist, notifications, project, repo, user, workflow, write:discussion, write:packages',
'x-ratelimit-limit': '5000',
'x-ratelimit-remaining': '4992',
'x-ratelimit-reset': '1716843733',
'x-ratelimit-resource': 'core',
'x-ratelimit-used': '8',
'x-xss-protection': '0'
},
data: {
message: 'Not Found',
documentation_url: 'https://docs.github.com/rest'
}
},
request: {
method: 'POST',
url: 'https://api.github.username/repos/u/repo_name/issues//labels',
headers: {
accept: 'application/vnd.github.-preview+json',
'user-agent': 'actions/github-script octokit-core.js/3.5.1 Node.js/16.20.2 (linux; x64)',
authorization: 'token [REDACTED]',
'content-type': 'application/json; charset=utf-8'
},
body: '{"labels":["done"]}',
request: { agent: [Agent], hook: [Function: bound bound register] }
}
How can I fix it?
Here is the code snippet shown below
name: Assign Label on Merge
on:
pull_request:
types: [closed]
jobs:
assign-label-on-merge:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- name: Check out the code
uses: actions/checkout@v2
- name: Assign Label to PR
uses: actions/github-script@v4
with:
github-token: ${{ secrets.CRM_PULL_REQUEST_TOKEN }}
script: |
github.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: ['done']
})
- name: Remove 'development' Label from PR
uses: actions/github-script@v4
with:
github-token: ${{ secrets.CRM_PULL_REQUEST_TOKEN }}
script: |
github.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
name: 'development'
})
- name: Find Connected Issue
id: find_issue
run: |
ISSUE_NUMBER=$(jq --raw-output .issue.number $GITHUB_EVENT_PATH)
echo "issue_number=$ISSUE_NUMBER" >> $GITHUB_ENV
if: github.event.pull_request.merged && github.event.pull_request.head.repo != github.event.pull_request.base.repo
- name: Assign Label to Issue
if: steps.find_issue.outputs.issue_number
uses: actions/github-script@v4
with:
github-token: ${{ secrets.CRM_PULL_REQUEST_TOKEN }}
script: |
github.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ env.issue_number }},
labels: ['done']
})
- name: Remove 'development' Label from Issue
if: steps.find_issue.outputs.issue_number
uses: actions/github-script@v4
with:
github-token: ${{ secrets.CRM_PULL_REQUEST_TOKEN }}
script: |
github.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ env.issue_number }},
name: 'development'
})