Skip to content
This repository has been archived by the owner on May 4, 2022. It is now read-only.

Commit

Permalink
Update messages to consistent with other SDMs
Browse files Browse the repository at this point in the history
  • Loading branch information
cdupuis committed Jun 10, 2019
1 parent 0290042 commit f842ec1
Show file tree
Hide file tree
Showing 6 changed files with 253 additions and 308 deletions.
101 changes: 31 additions & 70 deletions lib/handlers/commands/applyFingerprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import {
editModes,
GitProject,
guid,
logger,
ParameterType,
Project,
Expand All @@ -30,29 +29,27 @@ import {
AutoMergeMode,
} from "@atomist/automation-client/lib/operations/edit/editModes";
import { EditResult } from "@atomist/automation-client/lib/operations/edit/projectEditor";
import {
FP,
} from "@atomist/clj-editors";
import { FP } from "@atomist/clj-editors";
import {
CodeTransform,
CodeTransformRegistration,
CommandHandlerRegistration,
slackFooter,
slackInfoMessage,
slackSuccessMessage,
SoftwareDeliveryMachine,
} from "@atomist/sdm";
import { SlackMessage } from "@atomist/slack-messages";
import _ = require("lodash");
import {
bold,
codeLine,
} from "@atomist/slack-messages";
import * as _ from "lodash";
import { findTaggedRepos } from "../../adhoc/fingerprints";
import {
fromName,
queryPreferences,
} from "../../adhoc/preferences";
import {
Feature,
} from "../../machine/Feature";
import {
EditModeMaker,
} from "../../machine/fingerprintSupport";
import { Feature } from "../../machine/Feature";
import { EditModeMaker } from "../../machine/fingerprintSupport";
import { FindLinkedReposWithFingerprint } from "../../typings/types";

/**
Expand Down Expand Up @@ -95,19 +92,9 @@ async function pushFingerprint(
export function runAllFingerprintAppliers(registrations: Feature[]): CodeTransform<ApplyTargetFingerprintParameters> {
return async (p, cli) => {

const message: SlackMessage = {
attachments: [
{
author_name: "Apply target fingerprint",
author_icon: `https://images.atomist.com/rug/check-circle.gif?gif=${guid()}`,
text: `Applying target fingerprint \`${cli.parameters.fingerprint}\` to ${p.id.owner}/${p.id.repo}`,
mrkdwn_in: ["text"],
color: "#45B254",
fallback: "none",
footer: slackFooter(),
},
],
};
const message = slackInfoMessage(
"Apply Fingerprint Target",
`Applying fingerprint target ${codeLine(cli.parameters.fingerprint)} to ${bold(`${p.id.owner}/${p.id.repo}`)}`);

await cli.addressChannels(message, { id: cli.parameters.msgId });

Expand All @@ -132,19 +119,9 @@ export function runAllFingerprintAppliers(registrations: Feature[]): CodeTransfo
function runEveryFingerprintApplication(registrations: Feature[]): CodeTransform<ApplyTargetFingerprintsParameters> {
return async (p, cli) => {

const message: SlackMessage = {
attachments: [
{
author_name: "Apply target fingerprints",
author_icon: `https://images.atomist.com/rug/check-circle.gif?gif=${guid()}`,
text: `Applying target fingerprints \`${cli.parameters.fingerprints}\` to ${p.id.owner}/${p.id.repo}`,
mrkdwn_in: ["text"],
color: "#45B254",
fallback: "none",
footer: slackFooter(),
},
],
};
const message = slackInfoMessage(
"Apply Fingerprint Target",
`Applying fingerprint target ${codeLine(cli.parameters.fingerprints)} to ${bold(`${p.id.owner}/${p.id.repo}`)}`);

await cli.addressChannels(message, { id: cli.parameters.msgId });

Expand Down Expand Up @@ -190,7 +167,7 @@ export function applyTarget(

return {
name: ApplyTargetFingerprintName,
intent: "applyFingerprint",
intent: ["apply fingerprint target", "applyFingerprint"],
description: "choose to raise a PR on the current project to apply a target fingerprint",
parameters: {
msgId: { required: false, displayable: false },
Expand Down Expand Up @@ -269,13 +246,13 @@ export function broadcastFingerprintMandate(
.filter(repo => _.get(repo, "branches[0].commit.analysis"))
.filter(repo => repo.branches[0].commit.analysis.some(x => x.name === fp.name))
.map(repo => {
return {
owner: repo.owner,
repo: repo.name,
url: "url",
branch: "master",
};
},
return {
owner: repo.owner,
repo: repo.name,
url: "url",
branch: "master",
};
},
),
);
}
Expand Down Expand Up @@ -321,30 +298,14 @@ export function broadcastFingerprintMandate(
},
);

const message = slackSuccessMessage(
"Boardcast Fingerprint Target",
`Sent fingerprint pull request (${codeLine(i.parameters.fingerprint)}) to all impacted repositories
${result.map(x => `${x.target.name} (${x.success})`).join(", ")}`);

// replace the previous message where we chose this action
await i.addressChannels(
{
attachments: [
{
author_name: "Broadcast Fingerprint Target",
author_icon: `https://images.atomist.com/rug/check-circle.png`,
text: `We have sent a fingerprint PR (${i.parameters.fingerprint}) to all impacted Repos`,
fallback: `Boardcast PR`,
color: "#00cc00",
mrkdwn_in: ["text"],
footer: slackFooter(),
},
{
text: result.map(x => `${x.target.name} (${x.success})`).join(", "),
fallback: `Boardcast PR`,
color: "#00cc00",
mrkdwn_in: ["text"],
footer: slackFooter(),
},
],
},
{ id: i.parameters.msgId },
);
await i.addressChannels(message, { id: i.parameters.msgId });
},
parameters: {
msgId: { required: false, displayable: false },
Expand Down
140 changes: 62 additions & 78 deletions lib/handlers/commands/broadcast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ import {
actionableButton,
CommandHandlerRegistration,
CommandListenerInvocation,
slackFooter,
slackQuestionMessage,
slackWarningMessage,
} from "@atomist/sdm";
import {
codeLine,
italic,
SlackMessage,
user,
} from "@atomist/slack-messages";
import _ = require("lodash");
import * as _ from "lodash";
import { findTaggedRepos } from "../../adhoc/fingerprints";
import {
fromName,
Expand All @@ -52,48 +52,41 @@ export function askAboutBroadcast(cli: CommandListenerInvocation,
msgId: string): Promise<void> {
const author = cli.context.source.slack.user.id;

// always create a new message
return cli.addressChannels(
const message = slackQuestionMessage(
"Broadcast Fingerprint Target",
`Shall we send every affected repository a nudge or pull request for the new ${codeLine(toName(fp.type, fp.name))} target?`,
{
attachments:
[{
author_name: "Broadcast Fingerprint Target",
author_icon: `https://images.atomist.com/rug/warning-yellow.png`,
text: `Shall we nudge everyone with a PR for the new ${codeLine(`${toName(fp.type, fp.name)}`)} target?`,
fallback: `Broadcast PR for ${fp.type}::${fp.name}/${fp.sha}`,
color: "#ffcc00",
mrkdwn_in: ["text"],
actions: [
actionableButton(
{
text: "Broadcast Nudge",
},
BroadcastFingerprintNudge,
{
author,
msgId,
fingerprint: toName(fp.type, fp.name),
},
),
buttonForCommand(
{
text: "Broadcast PRs",
},
BroadcastFingerprintMandateName,
{
body: "broadcast PR everywhere",
title: "Broadcasting PRs",
branch: "master",
fingerprint: toName(fp.type, fp.name),
msgId,
},
),
],
footer: slackFooter(),
}],
actions: [
actionableButton(
{
text: "Broadcast Nudge",
},
BroadcastFingerprintNudge,
{
author,
msgId,
fingerprint: toName(fp.type, fp.name),
},
),
buttonForCommand(
{
text: "Broadcast PRs",
},
BroadcastFingerprintMandateName,
{
body: "broadcast PR everywhere",
title: "Broadcasting PRs",
branch: "master",
fingerprint: toName(fp.type, fp.name),
msgId,
},
),
],
},
{ id: msgId },
);

// always create a new message
return cli.addressChannels(message, { id: msgId });
}

// ------------------------------
Expand All @@ -119,9 +112,9 @@ function broadcastNudge(cli: CommandListenerInvocation<BroadcastFingerprintNudge
logger.info(
`findTaggedRepos(broadcastNudge)
${JSON.stringify(
data.Repo
.filter(repo => _.get(repo, "branches[0].commit.analysis"))
.filter(repo => repo.branches[0].commit.analysis.some(x => x.name === name)))}`);
data.Repo
.filter(repo => _.get(repo, "branches[0].commit.analysis"))
.filter(repo => repo.branches[0].commit.analysis.some(x => x.name === name)))}`);
return data.Repo
.filter(repo => _.get(repo, "branches[0].commit.analysis"))
.filter(repo => repo.branches[0].commit.analysis.some(x => x.name === name && x.type === type));
Expand All @@ -131,43 +124,34 @@ function broadcastNudge(cli: CommandListenerInvocation<BroadcastFingerprintNudge
sha: cli.parameters.sha,
},
(owner: string, repo: string, channel: string) => {
const message: SlackMessage = {
attachments: [
{
author_name: "Library Update",
author_icon: `https://images.atomist.com/rug/warning-yellow.png`,
text: `${user(cli.parameters.author)} has updated the target version of \`${cli.parameters.name}\`.
const message = slackWarningMessage(
"Fingerprint Target",
`${user(cli.parameters.author)} has updated the target version of ${codeLine(cli.parameters.name)}).
The reason provided is:
${italic(cli.parameters.reason)}`,
fallback: "Fingerprint Update",
mrkdwn_in: ["text"],
color: "#ffcc00",
},
{
text: `Shall we update project to use the new \`${cli.parameters.name}\` target?`,
fallback: "none",
actions: [
buttonForCommand(
{
text: "Update project",
},
ApplyTargetFingerprintName,
{
msgId,
fingerprint: cli.parameters.name,
title: `Updated target for ${cli.parameters.name} to ${cli.parameters.version}`,
body: cli.parameters.reason,
},
),
],
color: "#ffcc00",
footer: slackFooter(),
callback_id: "atm-confirm-done",
},
${italic(cli.parameters.reason)}`, cli.context);

message.attachments.push({
text: `Shall we update repository to use the new ${codeLine(cli.parameters.name)} target?`,
fallback: `Shall we update repository to use the new ${codeLine(cli.parameters.name)} target?`,
actions: [
buttonForCommand(
{
text: "Update",
},
ApplyTargetFingerprintName,
{
msgId,
fingerprint: cli.parameters.name,
title: `Updated target for ${cli.parameters.name} to ${cli.parameters.version}`,
body: cli.parameters.reason,
},
),
],
};
callback_id: "atm-confirm-done",
});

// each channel with a repo containing this fingerprint gets a message
// use the msgId passed in so all the msgIds across the different channels are the same
return cli.context.messageClient.addressChannels(message, channel, { id: msgId });
Expand Down
Loading

0 comments on commit f842ec1

Please sign in to comment.