Skip to content

Commit

Permalink
[skip ci] Merging into master from: test-bot-branch
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonolmstead33 authored Dec 14, 2016
2 parents 9759741 + 4e383f4 commit 1316c0d
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 32 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"https-proxy-agent": "^1.0.0",
"request": "^2.79.0",
"request-promise": "^4.1.1",
"shelljs": "^0.7.5",
"slack": "^8.1.2"
}
}
137 changes: 105 additions & 32 deletions src/github.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,74 @@
var rp = require('request-promise'),
HttpsProxyAgent = require('https-proxy-agent');;
HttpsProxyAgent = require('https-proxy-agent'),
Promise = require('bluebird'),
sh = require('shelljs');

const BASE_URL = "https://api.github.com/repos/";
const AUTH_URL = "https://github.com/login/oauth/authorize";
const OWNER = "Nordstrom/";
const REPO = "build-bot/";
const TOKEN = "access_token=0fe2c88a900ed9d2e13eaeb375176ccb3d4636d8";
const CLIENT_ID_AND_SECRET = "client_id=9536727b9f252ceb5e03&client_secret=8ebef8e5e15d50472b3656d70bd2cec5ad887e0f";
const BASIC_AUTH = "Basic amFzb25vbG1zdGVhZDMzOkJAc2ViYWxsMzM=";
const MERGE_MESSAGE = "Merging master into branch: ";
const MASTER_MERGE_MESSAGE = "[skip ci] Merging into master from: ";

var Github = {
commit : function(){
console.log("Committing...")
push : function(branch, message){
if (!branch){
return Promise.reject("No branch name on push");
}
var code = sh.exec('git add .');
if (code == 1){
return Promise.reject("Error on git add");
}
code = sh.exec('git commit -m "auto commit from bot: ' + message + '"');
if (code == 1){
return Promise.reject("Error on git commit");
}
code = sh.exec('git push origin ' + branch);
if (code == 1){
return Promise.reject("Error on git push");
}
return Promise.resolve();
},
authorizeAsync : function(){
var params = {
method : "GET",
uri : AUTH_URL + "?client_id=" + CLIENT_ID
};

if (!!process.env.LOCAL){
params.agent = new HttpsProxyAgent("http://webproxysea.nordstrom.net:8181");
preCheck : function(branch) {
if (!branch){
return Promise.reject("Invalid request -- need branch name")
}

return rp(params)
.then(function(data){
console.log(data);
return merge(branch, "master", MERGE_MESSAGE + branch)
.then(function(){
console.log("Success...");
})
.catch(function(err){
if (err.message.message.indexOf("409")){
return Promise.reject("Conflict merging master into " + branch);
} else {
return Promise.reject(err.message);
}
})
},
mergeAsync : function(base, head, message){
if (!base || !head || !message){
return Promise.reject("Invalid request")

mergeToMaster : function(branch) {
if (!branch) {
return Promise.reject("Invalid request -- need branch name")
}

return merge("master", branch, MASTER_MERGE_MESSAGE + branch)
.then(function () {
console.log("Success...");
})
.catch(function (err) {
if (err.message.message.indexOf("409")) {
return Promise.reject("Conflict merging " + branch + "into master");
} else {
return Promise.reject(err.message);
}
})
},

release : function(version, notes){
var params = {
uri : BASE_URL + OWNER + REPO + "merges",
uri : BASE_URL + OWNER + REPO + "releases",
method : "POST",
json : true,
headers : {
Expand All @@ -44,30 +78,69 @@ var Github = {
"Authorization" : BASIC_AUTH
},
body : {
"base": base,
"head": head,
"commit_message": message
"tag_name": "v" + version,
"target_commitish": "master",
"name": "RELEASE - v"+version,
"body": notes,
"draft": false,
"prerelease": false
}
};

if (!!process.env.LOCAL){
params.agent = new HttpsProxyAgent("http://webproxysea.nordstrom.net:8181");
}
params = checkProxy(params);

return rp(params)
.then(function(data){
console.log("DATA")
console.log("data");
console.log(data);
})
.catch(function(err){
console.log("ERR")
console.log(err.message);
console.log(err.response.headers);
console.log("err")
console.log(err);
})
}
};

module.exports = Github;

//Github.authorizeAsync()
Github.mergeAsync("test-bot-branch", "master", "First merge of bot branches")

function merge(base, head, message){
if (!base || !head || !message){
return Promise.reject("Invalid request, cant merge")
}

var params = {
uri : BASE_URL + OWNER + REPO + "merges",
method : "POST",
json : true,
headers : {
"Accept": "application/json",
"Content-Type": "application/json",
"User-Agent" : "Hackathon-Local-Dev",
"Authorization" : BASIC_AUTH
},
body : {
"base": base,
"head": head,
"commit_message": message
}
};

params = checkProxy(params);

return rp(params);
}

function checkProxy(params){
if (!!process.env.LOCAL){
params.agent = new HttpsProxyAgent("http://webproxysea.nordstrom.net:8181");
}
return params;
}




//** TEST CODE ****/
Github.push('test-bot-branch', "Testing skip ci");
// Github.release("0.0.1", "[skip ci]");

0 comments on commit 1316c0d

Please sign in to comment.