Skip to content

Instantly share code, notes, and snippets.

@cvakiitho
Created March 15, 2021 17:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cvakiitho/a24d37ee7e847148291f4fcaef1ece45 to your computer and use it in GitHub Desktop.
Save cvakiitho/a24d37ee7e847148291f4fcaef1ece45 to your computer and use it in GitHub Desktop.
Github Graphql branch protection rule
const fetch = require('node-fetch');
let url = 'https://<>.corp/api/graphql';
let options = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: 'Basic <base64 token>'
},
body: '{"query":"mutation createBranchProtectionRule($input:CreateBranchProtectionRuleInput!) {\n createBranchProtectionRule(input:$input){\n branchProtectionRule{\n id\n }\n } \n \n}\n","variables":{"input":{"repositoryId":"<repo_id>","pattern":"major*","dismissesStaleReviews":true,"requiresApprovingReviews":true,"requiredStatusCheckContexts":["continuous-integration/jenkins/pr-merge"],"requiredApprovingReviewCount":1,"isAdminEnforced":true,"requiresStrictStatusChecks":true,"requiresStatusChecks":true}},"operationName":"createBranchProtectionRule"}'
};
fetch(url, options)
.then(res => res.json())
.then(json => console.log(json))
.catch(err => console.error('error:' + err));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment