Skip to content

Commit

Permalink
style: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Aug 15, 2019
1 parent bcfd5f2 commit 9696e2e
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions lib/create-pr-on-change.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
module.exports = createPrOnChange;
module.exports = createPrOnChange

const execa = require("execa");
const { request } = require("@octokit/request");
const execa = require('execa')
const { request } = require('@octokit/request')

async function createPrOnChange() {
const [owner, repo] = process.env.TRAVIS_REPO_SLUG.split("/");
async function createPrOnChange () {
const [owner, repo] = process.env.TRAVIS_REPO_SLUG.split('/')
const branchName = `cron/webhooks-changes/${new Date()
.toISOString()
.substr(0, 10)}`;
.substr(0, 10)}`

// check if webhook files changed
const { stdout } = await execa("git", ["status"]);
const { stdout } = await execa('git', ['status'])
if (/nothing to commit/.test(stdout)) {
console.log("🤖 No changes detected in cron job.");
return;
console.log('🤖 No changes detected in cron job.')
return
}

console.log("🤖 Changes detected in cron job. Creating pull request ...");
console.log('🤖 Changes detected in cron job. Creating pull request ...')

// count changes
const diffResult = await execa("git diff --stat", { shell: true });
const diffResult = await execa('git diff --stat', { shell: true })
const changesSummary = diffResult.stdout
.split("\n")
.split('\n')
.pop()
.trim()
.replace(/file/, "webhook definition");
.replace(/file/, 'webhook definition')

// push changes back to GitHub
await execa("git", ["checkout", "-b", branchName]);
await execa("git", ["add", "cache"]);
await execa("git", ["commit", "-m", "build: cache"]);
await execa("git", ["add", "."]);
await execa("git", ["commit", "-m", "build: webhooks"]);
await execa("git", [
"push",
await execa('git', ['checkout', '-b', branchName])
await execa('git', ['add', 'cache'])
await execa('git', ['commit', '-m', 'build: cache'])
await execa('git', ['add', '.'])
await execa('git', ['commit', '-m', 'build: webhooks'])
await execa('git', [
'push',
`https://${process.env.GH_TOKEN}@github.com/${owner}/${repo}.git`,
`HEAD:${branchName}`
]);
await execa("git", ["checkout", "-"]);
])
await execa('git', ['checkout', '-'])

// start pullrequest
const { body } = await request(`POST /repos/:owner/:repo/pulls`, {
Expand All @@ -48,11 +48,11 @@ async function createPrOnChange() {
},
title: `🤖🚨 ${changesSummary}`,
head: branchName,
base: "master",
base: 'master',
body: `Dearest humans,
My friend Travis asked me to let you know that they found webhook changes in their daily routine check.`
});
})

console.log(`🤖 Pull request created: ${body.html_url}`);
console.log(`🤖 Pull request created: ${body.html_url}`)
}

0 comments on commit 9696e2e

Please sign in to comment.