Skip to content

Commit 70e4e0b

Browse files
revert-slack-channel-id (#46)
* Revert "Fix default (aka dev)" This reverts commit 5b16e3a. * Revert "Fix config in prod!" This reverts commit 81b0ceb. * Revert "Update Slack integration to use `channelId` instead of `channelName`" This reverts commit 42578e4.
1 parent 2bc6019 commit 70e4e0b

File tree

7 files changed

+23
-23
lines changed

7 files changed

+23
-23
lines changed

.github/workflows/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,4 @@ jobs:
6969
# sam build
7070
- run: sam build --use-container
7171
# sam deploy
72-
- run: sam deploy --no-confirm-changeset --no-fail-on-empty-changeset --parameter-overrides SlackTokenSecret=${{ secrets.SLACKTOKEN }} SmallImprovementsTokenSecret=${{ secrets.SITOKEN }} SlackChannelId=CF4U95FN0 ScheduleEnabled=true
72+
- run: sam deploy --no-confirm-changeset --no-fail-on-empty-changeset --parameter-overrides SlackTokenSecret=${{ secrets.SLACKTOKEN }} SmallImprovementsTokenSecret=${{ secrets.SITOKEN }} SlackChannel=goals ScheduleEnabled=true

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ An Event that is triggered by a rule deployed and updated automatically by [SAM]
2929
Serves as the main hub of this stack, deployed and updated automatically by [SAM](#sam).
3030

3131
- Triggered by a CloudWatch Event, which is passed into its main function.
32-
- Assigns its Slack Channel ID via Environment variables passed in by SAM.
32+
- Assigns its Slack Channel name via Environment variables passed in by SAM.
3333
- Uses the SecretsManager to get both the Slack and Small Improvements tokens.
3434
- Gets all objectives using the Small Improvements API token.
3535
- Filters the objectives such that only those of a specific type, status, visibility, and time are left.
3636
- Log the number of objectives found.
37-
- For each of those objectives, the database is checked to see if it has an object with the same ID (returns a promise).
37+
- For each of those objectives,the database is checked to see if it has an object with the same ID (returns a promise).
3838
- If the objective was in the database, return undefined, there is nothing left to do for this objective.
3939
- If the objective was not in the database, it will try to post to Slack, which requires the following:
4040
- Try to get SlackID via the email address in the Small Improvements Objective.
41-
- Format the Slack message using the objective, its status, and the SlackID.
41+
- Format the slack message using the objective, its status, and the SlackID.
4242
- Try to send the message (if successful, resolves to the body of the HTTP response).
4343
- Try to insert the record of the objective into the database.
4444
- Finally, after all of the promises created from those objectives resolve, the data on number of successful and unsuccessful posts is logged and returned.

src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ async function main(event, context) {
1717
Post message to Slack
1818
Put record in dynamodb
1919
*/
20-
const slackChannelId = process.env.SlackChannelId;
20+
const slackChannel = process.env.SlackChannel;
2121
const secrets = await secretsClient.getSecret();
2222
const objectiveActivities = await smallImprovementsClient.GetObjectives(secrets.SIToken);
2323
const { completed, created } = filter.filterActivities(objectiveActivities, new Date(event.time));
@@ -29,7 +29,7 @@ async function main(event, context) {
2929
const SIEmail = await smallImprovementsClient.GetEmail(activity.content.objective.owner.id, secrets.SIToken);
3030
await slackService.PostCompletedObjective(
3131
secrets.SlackToken,
32-
slackChannelId,
32+
slackChannel,
3333
activity.content,
3434
activity.change.newStatus.description,
3535
SIEmail
@@ -47,7 +47,7 @@ async function main(event, context) {
4747
const SIEmail = await smallImprovementsClient.GetEmail(activity.content.objective.owner.id, secrets.SIToken);
4848
await slackService.PostCreatedObjective(
4949
secrets.SlackToken,
50-
slackChannelId,
50+
slackChannel,
5151
activity.content,
5252
SIEmail
5353
);

src/slack-service.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
const slackClient = require('./slack');
22

33
// Get Slack ID, Format Message, Post
4-
async function PostCompletedObjective(token, channelId, content, newStatus, email) {
4+
async function PostCompletedObjective(token, channelName, content, newStatus, email) {
55
const slackID = await slackClient.getSlackID(email, token);
66
const formattedMessage = await slackClient.formatSlackMessageForCompleted(content.objective, newStatus, slackID, content.cycle.id);
7-
return await slackClient.slackPost(token, channelId, formattedMessage);
7+
return await slackClient.slackPost(token, channelName, formattedMessage);
88
}
9-
async function PostCreatedObjective(token, channelId, content, email) {
9+
async function PostCreatedObjective(token, channelName, content, email) {
1010
const slackID = await slackClient.getSlackID(email, token);
1111
const formattedMessage = await slackClient.formatSlackMessageForCreated(content.objective, slackID, content.cycle.id);
12-
return await slackClient.slackPost(token, channelId, formattedMessage);
12+
return await slackClient.slackPost(token, channelName, formattedMessage);
1313
}
1414

1515
exports.PostCompletedObjective = PostCompletedObjective;

src/slack.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ const messageVariables = {
44
};
55

66
// Post a message to a channel your app is in using ID and message text
7-
async function slackPost(authToken, channelId, formattedMessage) { // postData should be JSON, e.g. { channel:"#channel", text:'message' }
8-
formattedMessage.channel = '' + channelId;
7+
async function slackPost(authToken, channelName, formattedMessage) { // postData should be JSON, e.g. { channel:"#channel", text:'message' }
8+
formattedMessage.channel = '' + channelName;
99

1010
const options = {
1111
hostname: 'sourceallies.slack.com',

template.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ Parameters:
1010
Type: String
1111
Description: The slack token
1212
NoEcho: true
13-
SlackChannelId:
13+
SlackChannel:
1414
Type: String
15-
Description: The id of the slack channel to post messages to
16-
Default: C03HVBJ7WKC
15+
Description: The name of the slack channel to post messages to
16+
Default: si-sandbox
1717
ScheduleEnabled:
1818
Type: String
1919
Description: Whether the lambda scheduled trigger is enabled or not
@@ -37,7 +37,7 @@ Resources:
3737
Timeout: 300
3838
Environment:
3939
Variables:
40-
SlackChannelId: !Ref SlackChannelId
40+
SlackChannel: !Ref SlackChannel
4141
Policies:
4242
- DynamoDBCrudPolicy:
4343
TableName: !Ref DynamoTable

test/index.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ describe('index', () => {
1717
activities,
1818
dynamoRecords,
1919
objectiveId,
20-
slackChannelId,
20+
slackChannel,
2121
mockEmail;
2222

2323
afterEach(() => {
2424
jest.resetAllMocks();
2525
});
2626

2727
beforeEach(() => {
28-
slackChannelId = 'si-sandbox';
29-
process.env.SlackChannelId = slackChannelId;
28+
slackChannel = 'si-sandbox';
29+
process.env.SlackChannel = slackChannel;
3030

3131
eventDateString = '2022-06-02T00:00:00Z';
3232
event = {
@@ -112,7 +112,7 @@ describe('index', () => {
112112
expect(dynamodbClient.insertRecord).toHaveBeenCalledWith(activities.items[0].items[0].activities[1], 'CREATED');
113113
expect(slackClient.PostCompletedObjective).toHaveBeenCalledWith(
114114
secrets.SlackToken,
115-
slackChannelId,
115+
slackChannel,
116116
activities.items[0].items[0].activities[0].content,
117117
activities.items[0].items[0].activities[0].change.newStatus.description,
118118
mockEmail
@@ -147,14 +147,14 @@ describe('index', () => {
147147
expect(dynamodbClient.insertRecord).toHaveBeenCalledWith(activities.items[0].items[0].activities[1], 'CREATED');
148148
expect(slackClient.PostCompletedObjective).toHaveBeenCalledWith(
149149
secrets.SlackToken,
150-
slackChannelId,
150+
slackChannel,
151151
activities.items[0].items[0].activities[2].content,
152152
activities.items[0].items[0].activities[2].change.newStatus.description,
153153
mockEmail
154154
);
155155
expect(slackClient.PostCreatedObjective).toHaveBeenCalledWith(
156156
secrets.SlackToken,
157-
slackChannelId,
157+
slackChannel,
158158
activities.items[0].items[0].activities[1].content,
159159
mockEmail
160160
);

0 commit comments

Comments
 (0)