Skip to content

Commit

Permalink
First complete version
Browse files Browse the repository at this point in the history
Dummy config :)
  • Loading branch information
Ninban committed Jan 31, 2019
1 parent 01b8577 commit 967216d
Show file tree
Hide file tree
Showing 5 changed files with 322 additions and 112 deletions.
14 changes: 0 additions & 14 deletions handler.js

This file was deleted.

239 changes: 239 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "puller",
"version": "1.0.0",
"description": "puller",
"main": "puller.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "MIT",
"dependencies": {
"@octokit/rest": "^16.13.3",
"xmlhttprequest": "^1.8.0"
}
}
56 changes: 56 additions & 0 deletions puller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
global.XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;

const Octokit = require('@octokit/rest');

exports.puller = async () => {
const openMergeRequest = () => {
const octokit = new Octokit({
auth: `token ${process.env.GITHUB_TOKEN}`
});
return octokit.pulls.create({
owner: process.env.baseRepoOwner,
repo: process.env.repoName,
head: `${process.env.headRepoOwner}:${process.env.headRepoBranch}`,
base: process.env.baseRepoBranch,
title: 'Automatic syncing pull request',
body: `Automatic syncing pull request for ${new Date()}`,
maintainer_can_modify: false
});
};

const handleError = error => {
if (error.name === "HttpError" &&
error.status === 422 &&
error.errors) {
let message = error.errors[0].message;
if (message.includes('No commits between'))
return {
status: 'Success',
message: 'No commits found'
};
else if (message.includes('A pull request already exists'))
return {
status: 'Success',
message: 'A pull request already exists'
};
else
return error;
} else
return error;
};

return openMergeRequest()
.then(() => {
const message = {
status: 'Success',
message: 'Pull request created'
};
console.log(message);
return message;
})
.catch(error => {
const message = handleError(error);
console.log(message);
return message;
});
};
Loading

0 comments on commit 967216d

Please sign in to comment.