Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ module.exports.getGithubCommit = async (build, octokit) => {
// subscribe is the main function called by GCF.
module.exports.subscribe = async (event) => {
try {
const token = process.env.GITHUB_TOKEN;
const octokit = token && new Octokit({
auth: `token ${token}`,
});
// Format data
const build = module.exports.eventToBuild(event.data);

// Skip if the current status is not in the status list.
Expand All @@ -43,9 +40,20 @@ module.exports.subscribe = async (event) => {
return;
}

const githubCommit = await module.exports.getGithubCommit(build, octokit);
// If specified get information from GitHub
const token = process.env.GITHUB_TOKEN;
let githubCommit = null;
if (token) {
const octokit = token && new Octokit({
auth: `token ${token}`,
});

githubCommit = await module.exports.getGithubCommit(build, octokit);
}

// Format final message
const message = await module.exports.createSlackMessage(build, githubCommit);

// Send message to slack.
module.exports.webhook.send(message);
} catch (err) {
Expand Down