Skip to content

Instantly share code, notes, and snippets.

@marccampbell
Last active February 8, 2020 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marccampbell/a3d1b6aad604c90546507fc2aa913946 to your computer and use it in GitHub Desktop.
Save marccampbell/a3d1b6aad604c90546507fc2aa913946 to your computer and use it in GitHub Desktop.
#!/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);
})
})
@marccampbell
Copy link
Author

Running this with file = '.github/workflows/test.yaml' results in a 403, but running this with file = '.github/my-app/test.yaml' results in a 201

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