-
-
Save marccampbell/a3d1b6aad604c90546507fc2aa913946 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/node | |
const { App } = require("@octokit/app"); | |
const { request } = require("@octokit/request"); | |
const APP_ID = 0; // set this to a valid app with contents = read/write permissions | |
const owner = 'marccampbell'; | |
const repo = 'gitops-dev'; | |
const installationId = 0; // set to an installation id of the above app | |
const PRIVATE_KEY = "-----BEGIN RSA PRIVATE KEY-----\nMII... <cut> \n"; | |
const app = new App({ id: APP_ID, privateKey: PRIVATE_KEY }); | |
// ****** | |
// | |
// The following variable (file) illustrates the problem. | |
// If the file is in .github/workflows (or, interestingly, .github/workflow) | |
// then the github api returns a 403. Any other path returns a 201. | |
// | |
// ****** | |
// var file = '.github/my-app/test.yaml'; // works (201) | |
var file = '.github/workflows/test.yaml'; // does not work (403) | |
app.getInstallationAccessToken({ | |
installationId | |
}) | |
.then((installationAccessToken) => { | |
request("PUT /repos/:owner/:repo/contents/:file", { | |
owner, | |
repo, | |
file, | |
headers: { | |
authorization: `token ${installationAccessToken}`, | |
accept: "application/vnd.github.machine-man-preview+json" | |
}, | |
message: "test", | |
content: "data", | |
}) | |
.then((res) => { | |
console.log("success", res.status); | |
}) | |
.catch((err) => { | |
console.log("error", err.status); | |
}) | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Running this with
file = '.github/workflows/test.yaml'
results in a 403, but running this withfile = '.github/my-app/test.yaml'
results in a 201