1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.announceTransformResults = void 0;
|
19 | const editModes_1 = require("@atomist/automation-client/lib/operations/edit/editModes");
|
20 | const messages_1 = require("../../misc/slack/messages");
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | async function announceTransformResults(trs, cli) {
|
29 | const messages = trs.map(tr => {
|
30 | const projectId = tr.target.id;
|
31 | const title = `${projectId.owner}/${projectId.repo}`;
|
32 | if (tr.error) {
|
33 | return messages_1.slackErrorMessage(title, "Failure in " + cli.commandName + "\n```\n" + tr.error.message + "\n```", cli.context, {
|
34 | author_name: title,
|
35 | author_link: tr.target.id.url,
|
36 | });
|
37 | }
|
38 | if (tr.edited) {
|
39 | return messages_1.slackSuccessMessage(title, "Successfully applied " + cli.commandName, {
|
40 | fields: fromEditMode(tr.editMode),
|
41 | author_name: title,
|
42 | author_link: tr.target.id.url,
|
43 | });
|
44 | }
|
45 | return messages_1.slackInfoMessage(title, "No changes made by " + cli.commandName, {
|
46 | author_name: title,
|
47 | author_link: tr.target.id.url,
|
48 | });
|
49 | });
|
50 | await asyncForEach(messages, message => cli.addressChannels(message));
|
51 | }
|
52 | exports.announceTransformResults = announceTransformResults;
|
53 | async function asyncForEach(array, fn) {
|
54 | return Promise.all(array.map(fn));
|
55 | }
|
56 | function fromEditMode(editMode) {
|
57 | if (!editMode) {
|
58 | return [];
|
59 | }
|
60 | const fields = [];
|
61 | if (editModes_1.isBranchCommit(editMode)) {
|
62 | fields.push({
|
63 | title: "branch",
|
64 | value: editMode.branch,
|
65 | short: false,
|
66 | });
|
67 | }
|
68 | if (editModes_1.isPullRequest(editMode)) {
|
69 | fields.push({
|
70 | title: "Pull Request title",
|
71 | value: editMode.title,
|
72 | short: false,
|
73 | });
|
74 | if (!!editMode.targetBranch) {
|
75 | fields.push({
|
76 | title: "target branch",
|
77 | value: editMode.targetBranch,
|
78 | short: false,
|
79 | });
|
80 | }
|
81 | if (!!editMode.autoMerge) {
|
82 | fields.push({
|
83 | title: "AutoMerge mode",
|
84 | value: editMode.autoMerge.mode,
|
85 | short: false,
|
86 | });
|
87 | if (!!editMode.autoMerge.method) {
|
88 | fields.push({
|
89 | title: "AutoMerge method",
|
90 | value: editMode.autoMerge.method,
|
91 | short: false,
|
92 | });
|
93 | }
|
94 | }
|
95 | }
|
96 | return fields;
|
97 | }
|
98 |
|
\ | No newline at end of file |