kaizensoze/node-github

Delete a branch

AdrienLemaire opened this issue · 2 comments

Hi, thank you for maintaining this fork of node-github, working well so far.

I would like to auto-delete a branch after its pull request got merged, but I cannot find a deleteBranch method. How would you do that ?

Thank you

Thank you, I got it :)

Here a snippet if other people are interested

require('dotenv').config();                                                                                        
var prettyjson = require('prettyjson');                                                                            
var GitHubApi = require("github4");                                                                                

var github = new GitHubApi({                                                                                       
    // optional                                                                                                    
    debug: true,                                                                                                   
    protocol: "https",                                                                                             
    host: 'api.github.com',                                                                                        
    pathPrefix: "",                                                                                                
    timeout: 5000                                                                                                  });                                                                                                                                                                                                                                   
github.authenticate({type:"oauth", token: process.env.GH_TOKEN});                                                  

var params = {                                                                                                     
  user: process.env.GH_USER,                                                                                       
  repo: process.env.GH_REPO,                                                                                       
  number: 3                                                                                                        
};                                                                                                                 
//github.gitdata.getReferences(params, function(err,pr) {                                                          
  //if (err) { console.log(JSON.stringify(err)); }                                                                 
  //else { console.log(prettyjson.render(pr)); }                                                                   
//});                                                                                                              
github.pullRequests.get(params, function(err, pr) {                                                                
  if (err) { console.log(JSON.stringify(err)); }                                                                   
  else {                                                                                                           
    console.log(prettyjson.render(pr));                                                                            
    params.ref = 'heads/' + pr.head.ref;                                                                           
    github.gitdata.deleteReference(params);                                                                        
    }                                                                                                              
  }                                                                                                                
);