Skip to content

Instantly share code, notes, and snippets.

@marccampbell marccampbell/create-file-error.js Secret
Last active Feb 8, 2020

Embed
What would you like to do?
#!/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

This comment has been minimized.

Copy link
Owner Author

marccampbell commented Feb 8, 2020

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
You can’t perform that action at this time.