kaizensoze / node-github

[DEPRECATED] Node.js wrapper for GitHub API
https://kaizensoze.github.io/node-github/
MIT License
29 stars 5 forks source link

Delete a branch #99

Closed AdrienLemaire closed 8 years ago

AdrienLemaire commented 8 years ago

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

kaizensoze commented 8 years ago

That should be under Git Data:

https://kaizensoze.github.io/node-github/#api-gitdata-deleteReference https://developer.github.com/v3/git/refs/#delete-a-reference

AdrienLemaire commented 8 years ago

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);                                                                        
    }                                                                                                              
  }                                                                                                                
);