Octokit is encoding path of /contents/ api resulting in 403 #2182
-
Hello all! Hope I am doing this correctly. I am using the octokit in probot and is causing this problem. I am trying to create a new file. When I do: return context.octokit.repos.createOrUpdateFileContents({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
path: 'initial.yaml', // <-- works fine
content: Buffer.from(initialAction).toString('base64'),
message: 'ci: create initial PR verification process',
committer: signature,
author: signature
}); this works fine. But when I give a sub path for the same file in the same repository it fails. Request: return context.octokit.repos.createOrUpdateFileContents({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
path: '.github/workflows/initial.yaml', // <-- desired path
content: Buffer.from(initialAction).toString('base64'),
message: 'ci: create initial PR verification process',
committer: signature,
author: signature
}); And the error: status: 403
request: {
method: "PUT"
url: "https://[GHES]/api/v3/repos/[REDACTED]/webhook-test/contents/.github%2Fworkflows%2Finitial.yaml"
headers: {
"accept": "application/vnd.github.v3+json",
"user-agent": "probot/11.4.1 octokit-core.js/3.5.1 Node.js/16.13.1 (darwin; x64)",
"authorization": "token [REDACTED]",
"content-type": "application/json; charset=utf-8"
}
body: "{\"content\":\"b246CiAgcHVsbF9yZXF1ZXN0X3RhcmdldDoKICAgIHR5cGVzOgogICAgICAtIGVkaXRlZAogICAgICAtIG9wZW5lZAogICAgICAtIHJlb3BlbmVkCiAgICAgIC0gcmVhZHlfZm9yX3JldmlldwogICAgICAtIHN5bmNocm9uaXplCgpqb2JzOgogIERhbmdlcjoKICAgIHJ1bnMtb246IHNlbGYtaG9zdGVkCiAgICBzdGVwczoKICAgICAgLSBydW46IGVjaG8gIlRoaXMgaXMganVzdCBhIHNhbXBsZSBkYW5nZXIiCgogIFZlcmlmeToKICAgIHJ1bnMtb246IHNlbGYtaG9zdGVkCiAgICBzdGVwczoKICAgICAgLSBydW46IGVjaG8gIlRoaXMgaXMganVzdCBhIHNhbXBsZSB2ZXJpZnkiCg==\",\"message\":\"ci: create initial PR verification process\",\"committer\":{\"name\":\"[REDACTED]\",\"email\":\"[REDACTED]\"},\"author\":{\"name\":\"[REDACTED]\",\"email\":\"[REDACTED]\"}}"
request: {}
} My suspicion is the Any help would be much appreciated |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Found the solution. I have to allow "Workflows" permission to the application. It was working fine for other files because it already has "Contents" permission. |
Beta Was this translation helpful? Give feedback.
Found the solution. I have to allow "Workflows" permission to the application. It was working fine for other files because it already has "Contents" permission.