Skip to content

Commit

Permalink
Fix yarn lint issues and add yarn.lock
Browse files Browse the repository at this point in the history
  • Loading branch information
Omicron7 committed Jun 10, 2020
1 parent 6d00c36 commit 1f99125
Show file tree
Hide file tree
Showing 4 changed files with 11,056 additions and 58 deletions.
2 changes: 1 addition & 1 deletion config/rollbar.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const Rollbar = require('rollbar');
const Rollbar = require('rollbar')

const rollbar = new Rollbar({
// https://rollbar.com/docs/notifier/rollbar.js/#configuration-reference
Expand Down
107 changes: 53 additions & 54 deletions src/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,103 +5,102 @@ const { rollbar } = require('../config/rollbar.js')
module.exports = app => {
const defaultConfig = {
enabled: false,
label_name: "On Staging",
label_name: 'On Staging',
comment: true
};
}

app.router.use(rollbar.errorHandler())

app.log("Yay, the app was loaded!");
app.log('Yay, the app was loaded!')

app.on("pull_request.labeled", async context => {
const senderType = context.payload.sender.type;
if (senderType == "Bot") return;
app.on('pull_request.labeled', async context => {
const senderType = context.payload.sender.type
if (senderType === 'Bot') return

const labelName = context.payload.label.name;
const config = await loadConfig(context);
if (labelName != config.label_name) return;
const labelName = context.payload.label.name
const config = await loadConfig(context)
if (labelName !== config.label_name) return
if (!config.enabled) {
app.log("Label added, but no action taken because config is disabled.")
return;
app.log('Label added, but no action taken because config is disabled.')
return
}

mergeBranchIntoStaging(context);
mergeBranchIntoStaging(context)
if (config.comment) {
const commentBody = `I see you added the "${config.label_name}" label, I'll get this merged to the staging branch!`;
addComment(commentBody, context);
const commentBody = `I see you added the "${config.label_name}" label, I'll get this merged to the staging branch!`
addComment(commentBody, context)
}
});
})

app.on(["issue_comment.created", "issue_comment.edited"], async context => {
const message = context.payload.comment.body;
app.on(['issue_comment.created', 'issue_comment.edited'], async context => {
const message = context.payload.comment.body
if (message.match(/merge to stag((ing)|e)/i)) {
const config = await loadConfig(context);
const config = await loadConfig(context)

if (!config.enabled) {
app.log("Comment observed, but no action taken because config is disabled.")
app.log('Comment observed, but no action taken because config is disabled.')
app.log(message)
return;
return
}

mergeBranchIntoStaging(context);
addLabel(context, config.label_name);
if (config.comment)
addComment("I'll get this merged to the staging branch!", context);
mergeBranchIntoStaging(context)
addLabel(context, config.label_name)
if (config.comment) { addComment("I'll get this merged to the staging branch!", context) }
}
});
})

app.on("pull_request.synchronize", async context => {
const config = await loadConfig(context);
if (!config.enabled) return;
app.on('pull_request.synchronize', async context => {
const config = await loadConfig(context)
if (!config.enabled) return
if (await pullRequestHasLabel(context, config.label_name)) {
mergeBranchIntoStaging(context);
mergeBranchIntoStaging(context)
}
});
})

async function loadConfig(context) {
return await context.config("merge-bot.yml", defaultConfig);
async function loadConfig (context) {
return await context.config('merge-bot.yml', defaultConfig)
}

async function pullRequestHasLabel(context, labelName) {
async function pullRequestHasLabel (context, labelName) {
const { data: labels } = await context.github.issues.listLabelsOnIssue(
context.issue()
);
)
for (const l of labels) {
if (l.name == labelName) {
return true;
if (l.name === labelName) {
return true
}
}
}

async function mergeBranchIntoStaging(context) {
const { data: prDetails } = await context.github.pulls.get(context.issue());
async function mergeBranchIntoStaging (context) {
const { data: prDetails } = await context.github.pulls.get(context.issue())
const mergePayload = context.repo({
base: "staging",
base: 'staging',
head: prDetails.head.ref
});
})
context.github.repos.merge(mergePayload).catch(error => {
mergeError(error, context);
});
mergeError(error, context)
})
}

function addLabel(context, labelName) {
const addLabelPayload = context.issue({ labels: [labelName] });
context.github.issues.addLabels(addLabelPayload);
function addLabel (context, labelName) {
const addLabelPayload = context.issue({ labels: [labelName] })
context.github.issues.addLabels(addLabelPayload)
}

function addComment(message, context) {
const pullRequestComment = context.issue({ body: message });
return context.github.issues.createComment(pullRequestComment);
function addComment (message, context) {
const pullRequestComment = context.issue({ body: message })
return context.github.issues.createComment(pullRequestComment)
}

function mergeError(error, context) {
if (error.message == "Merge conflict") {
function mergeError (error, context) {
if (error.message === 'Merge conflict') {
addComment(
"Merge conflict attempting to merge this into staging. Please fix manually.",
'Merge conflict attempting to merge this into staging. Please fix manually.',
context
);
)
} else {
app.log(error);
app.log(error)
}
}
};
}
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { Probot } = require("probot");
const app = require("./bot.js");
const { Probot } = require('probot')
const app = require('./bot.js')

// pass a probot app as a function
Probot.run(app);
Probot.run(app)
Loading

0 comments on commit 1f99125

Please sign in to comment.