Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const sanitizeMarkdown = (markdown: string) =>
githubToSlack(markdown)
.split('\n')
.map(line => {
// Strip out the ### prefix and replace it with ** to make it bold
if (line.startsWith('#')) {
return `*${line.replace(/^[#]+/, '')}*`;
}
return line;
})
.join('\n');
retryButton?: slack.Action): Promise {
if (!interpretation) {
if (fullLog.url) {
logger.debug("No log interpretation. Log available at: " + fullLog.url);
return;
}
logger.debug("No log interpretation, no log URL. Sending full log to Slack");
await addressChannels({
content: fullLog.log,
fileType: "text",
fileName: `${stepName}-failure-${id.sha}.log`,
} as any);
return;
}
await addressChannels({
text: `Failed ${stepName} of ${slack.url(`${id.url}/tree/${id.sha}`, id.sha.substr(0, 7))}`,
attachments: [{
title: interpretation.message || "Failure",
title_link: fullLog.url,
fallback: "relevant bits",
text: interpretation.relevantPart,
color: "#ff5050",
actions: retryButton ? [retryButton] : [],
}],
});
const includeFullLogByDefault = !fullLog.url; // if there is no link, include it by default
const shouldIncludeFullLog = "includeFullLog" in interpretation ? interpretation.includeFullLog : includeFullLogByDefault;
if (shouldIncludeFullLog) {
logger.debug("sending full log to slack. url is %s, includeFullLog is %s", fullLog.url, interpretation.includeFullLog);
await addressChannels({
content: fullLog.log,
fileType: "text",
...params,
};
pi.credentials = await resolveCredentialsPromise(pi.credentials);
// It's a function that takes the parameters and returns either a project or a RemoteRepoRef
const rr: RemoteRepoRef | Project | Promise = (startingPoint as any)(pi);
if (isProjectPromise(rr)) {
const p = await rr;
await infoMessage(`Using dynamically chosen starting point project ${bold(`${p.id.owner}:${p.id.repo}`)}`, ctx);
return p;
}
if (isProject(rr)) {
await infoMessage(`Using dynamically chosen starting point project ${bold(`${rr.id.owner}:${rr.id.repo}`)}`, ctx);
// params.source will remain undefined in this case
return rr;
} else {
await infoMessage(`Cloning dynamically chosen starting point from ${url(rr.url)}`, ctx);
params.source = { repoRef: rr };
return repoLoader(rr);
}
}
}
code: 0,
// Redirect to local project page
redirect: details.redirecter(params.target.repoRef),
// local SDM uses this to print instructions
generatedRepositoryUrl: params.target.repoRef.url,
} as any;
} catch (err) {
if (err instanceof CommandListenerExecutionInterruptError) {
// We're continuing
return Success as any;
}
await ctx.messageClient.respond(
slackErrorMessage(
`Create Project`,
`Project creation for ${bold(`${params.target.repoRef.owner}/${params.target.repoRef.repo}`)} failed:
${codeBlock(err.message)}`,
ctx));
}
}
codeTransformName,
{
// reuse the other parameters, but set the dryRun flag to false and pin to one repo
...params,
"dry-run": false,
"dry-run.msgId": msgId,
"targets.sha": params.targets.sha,
"targets.owner": id.owner,
"targets.repo": id.repo,
}),
],
};
await ctx.messageClient.respond(
slackInfoMessage(
`Code Transform (dry run)`,
`Code transform ${italic(codeTransformName)} would make the following changes to ${bold(slug(id))}:
${codeBlock(diff)}
`, applyAction), { id: msgId });
}
// Redirect to local project page
redirect: details.redirecter(params.target.repoRef),
// local SDM uses this to print instructions
generatedRepositoryUrl: params.target.repoRef.url,
} as any;
} catch (err) {
if (err instanceof CommandListenerExecutionInterruptError) {
// We're continuing
return Success as any;
}
await ctx.messageClient.respond(
slackErrorMessage(
`Create Project`,
`Project creation for ${bold(`${params.target.repoRef.owner}/${params.target.repoRef.repo}`)} failed:
${codeBlock(err.message)}`,
ctx));
}
}
{
// reuse the other parameters, but set the dryRun flag to false and pin to one repo
...params,
"dry-run": false,
"dry-run.msgId": msgId,
"targets.sha": params.targets.sha,
"targets.owner": id.owner,
"targets.repo": id.repo,
}),
],
};
await ctx.messageClient.respond(
slackInfoMessage(
`Code Transform (dry run)`,
`Code transform ${italic(codeTransformName)} would make the following changes to ${bold(slug(id))}:
${codeBlock(diff)}
`, applyAction), { id: msgId });
}
public handle(e: EventFired, ctx: HandlerContext): Promise {
const push = e.data.GitLabPush[0];
const text = `${push.commits.length} new ${(push.commits.length > 1 ? "commits" : "commit")} ` +
`to ${bold(url(push.repository.git_http_url, `${push.user_username}/${push.repository.name}/master`))}`;
const msg: SlackMessage = {
text,
attachments: [{
fallback: text,
author_name: `@${push.user_username}`,
author_icon: push.user_avatar,
text: push.commits.map(c => `\`${url(c.url, c.id.slice(0, 7))}\` ${c.message.slice(0, 49)}`).join("\n"),
mrkdwn_in: ["text"],
color: "#00a5ff",
},
],
};
return ctx.messageClient.send(msg, addressSlackChannels("FIXME", "gitlab"))
.then(() => Success, failure);
}
}
owner: cli.parameters.targets.repoRef.owner,
repo: cli.parameters.targets.repoRef.repo,
});
} catch (e) {
const text = `Repository ${bold(slug)} not found`;
return cli.context.messageClient.respond(slackWarningMessage("Set Goal State", text, cli.context));
}
const branch = cli.parameters.targets.repoRef.branch || repoData.defaultBranch;
let sha;
try {
sha = cli.parameters.targets.repoRef.sha || tipOfBranch(repoData, branch);
} catch (e) {
return cli.context.messageClient.respond(
slackWarningMessage(
"Set Goal State",
`Branch ${bold(branch)} not found on ${bold(slug)}`,
cli.context));
}
const id = GitHubRepoRef.from({
owner: cli.parameters.targets.repoRef.owner,
repo: cli.parameters.targets.repoRef.repo,
sha,
branch,
});
const push = await fetchPushForCommit(cli.context, id, cli.parameters.providerId);
const goals = await chooseAndSetGoals(rules, {
context: cli.context,
credentials: cli.credentials,
push,
branch,
});
const push = await fetchPushForCommit(cli.context, id, cli.parameters.providerId);
const goals = await chooseAndSetGoals(rules, {
context: cli.context,
credentials: cli.credentials,
push,
});
const slugBranch = `${id.owner}/${id.repo}/${push.branch}`;
if (goals) {
await cli.addressChannels(slackSuccessMessage(
"Plan Goals",
`Successfully planned goals on ${codeLine(push.after.sha.slice(0, 7))} of ${bold(slugBranch)} to ${italic(goals.name)}`,
{
footer: `${cli.parameters.name}:${cli.parameters.version}`,
}));
} else {
await cli.addressChannels(slackWarningMessage(
"Plan Goals",
`No goals found for ${codeLine(push.after.sha.slice(0, 7))} of ${bold(slugBranch)}`,
cli.context,
{
footer: `${cli.parameters.name}:${cli.parameters.version}`,
}));
}
return Success;
};
}