Skip to content

Instantly share code, notes, and snippets.

@adityak74
Last active September 2, 2021 15:10
Show Gist options
  • Save adityak74/a9655bf7eff5879f6db72cd4952c0787 to your computer and use it in GitHub Desktop.
Save adityak74/a9655bf7eff5879f6db72cd4952c0787 to your computer and use it in GitHub Desktop.

Revisions

  1. adityak74 renamed this gist Sep 2, 2021. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. adityak74 revised this gist Sep 2, 2021. 1 changed file with 12 additions and 7 deletions.
    19 changes: 12 additions & 7 deletions merge-all-pull-request,js
    Original file line number Diff line number Diff line change
    @@ -18,13 +18,18 @@ async function mergeAllPullRequests() {
    }).then(async ({ data }) => {
    for(let i = 0; i < data.length; i++) {
    console.info('Merging PR', data[i].number);
    const mergeData = await octokit.rest.pulls.merge({
    owner: "adityak74",
    repo: "cryptoviz",
    pull_number: data[i].number,
    merge_method: "squash"
    });
    console.info(`${mergeData.data.message} with hash : ${mergeData.data.sha}`);
    try {
    const mergeData = await octokit.rest.pulls.merge({
    owner: "adityak74",
    repo: "newfields-app",
    pull_number: data[i].number,
    merge_method: "squash"
    });
    console.info(`${mergeData.data.message} with hash : ${mergeData.data.sha}`);
    } catch (error) {
    console.error(error);
    continue;
    }
    }
    }).catch(err => {
    console.error('Error listing pull requests', err);
  3. adityak74 created this gist Sep 2, 2021.
    34 changes: 34 additions & 0 deletions merge-all-pull-request,js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    const { Octokit } = require("octokit");
    const dotenv = require('dotenv');
    const path = require('path');

    // to load the PAT you created
    dotenv.config({ path: path.join(__dirname, '..', '..', `.env.${process.env.NODE_ENV || 'development'}`) });

    // Create a personal access token at https://github.com/settings/tokens/new?scopes=repo
    const octokit = new Octokit({ auth: process.env.GIT_PAT });

    // Compare: https://docs.github.com/en/rest/reference/users#get-the-authenticated-user
    async function mergeAllPullRequests() {
    await octokit.rest.users.getAuthenticated();
    octokit.rest.pulls.list({
    owner: "gitusername",
    repo: "yourrepo",
    state: "open"
    }).then(async ({ data }) => {
    for(let i = 0; i < data.length; i++) {
    console.info('Merging PR', data[i].number);
    const mergeData = await octokit.rest.pulls.merge({
    owner: "adityak74",
    repo: "cryptoviz",
    pull_number: data[i].number,
    merge_method: "squash"
    });
    console.info(`${mergeData.data.message} with hash : ${mergeData.data.sha}`);
    }
    }).catch(err => {
    console.error('Error listing pull requests', err);
    });
    }

    mergeAllPullRequests();