-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dummy config :)
- Loading branch information
Showing
5 changed files
with
322 additions
and
112 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); | ||
}; |
Oops, something went wrong.