-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
creating new webhook for the options-automator #554
Changes from 8 commits
57e0609
a723d02
2859a36
15605c4
a0d4f27
0c06fbb
890703b
7bbe577
e139909
58156d0
abb877a
9b8fbb9
b9a5b8a
0f72c93
a5a90ee
828ef15
a539189
383808e
533367a
76fcfa0
82df7bb
5ffcdd0
ff72728
096fe63
a889c6c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,8 @@ export const GOCD_ORIGIN = | |
process.env.GOCD_ORIGIN || 'https://deploy.getsentry.net'; | ||
export const FEED_DEPLOY_CHANNEL_ID = | ||
process.env.FEED_DEPLOY_CHANNEL_ID || 'C051ED5GLN4'; | ||
export const FEED_OPTIONS_AUTOMATOR_CHANNEL_ID = | ||
process.env.FEED_OPTIONS_AUTOMATOR_CHANNEL_ID || 'C05JJ5JNZAB'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where did you pick this channel id? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this was my test channel id while I was testing locally, will correct it before merging. |
||
export const FEED_DEV_INFRA_CHANNEL_ID = | ||
process.env.FEED_DEV_INFRA_CHANNEL_ID || 'C05816N2A2K'; | ||
export const FEED_ENGINEERING_CHANNEL_ID = | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,7 +65,7 @@ export type CheckRun = EmitterWebhookEvent<'check_run'>['payload']['check_run']; | |
// | ||
// Need to do this as we can't convert a string literal union to an array of literals | ||
export const CHECK_RUN_PROPERTIES = ['id', 'head_sha', 'html_url'] as const; | ||
export type CheckRunProperty = typeof CHECK_RUN_PROPERTIES[number]; | ||
export type CheckRunProperty = (typeof CHECK_RUN_PROPERTIES)[number]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this change ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems like an autoformatting change I didn't make this change |
||
export type CheckRunForRequiredChecksText = Pick<CheckRun, CheckRunProperty>; | ||
|
||
export type GoCDResponse = GoCDStageResponse | GoCDAgentResponse; | ||
|
@@ -170,3 +170,12 @@ type GoCDApprovalType = 'success' | 'manual'; | |
type GoCDResultType = 'Passed' | 'Failed' | 'Cancelled' | 'Unknown'; | ||
|
||
type GoCDStateType = 'Passed' | 'Failed' | 'Cancelled' | 'Building'; | ||
|
||
export interface OptionsAutomatorResponse { | ||
drifted_options: { option_name: string; option_value: string }[]; | ||
channel_updated_options: string[]; | ||
updated_options: { option_name: string; db_value: string; value: string }[]; | ||
set_options: { option_name: string; option_value: string }[]; | ||
unset_options: string[]; | ||
error_options: { option_name: string; error_msg: string }[]; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { handler } from './options-automator'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import { KnownBlock, SectionBlock } from '@slack/types'; | ||
import { FastifyRequest } from 'fastify'; | ||
|
||
import { OptionsAutomatorResponse } from '@types'; | ||
|
||
import { bolt } from '@/api/slack'; | ||
import * as slackblocks from '@/blocks/slackBlocks'; | ||
import { FEED_OPTIONS_AUTOMATOR_CHANNEL_ID } from '@/config'; | ||
|
||
export async function handler( | ||
request: FastifyRequest<{ Body: OptionsAutomatorResponse }> | ||
) { | ||
const { body }: { body: OptionsAutomatorResponse } = request; | ||
await messageSlack(body); | ||
return {}; | ||
} | ||
|
||
export async function messageSlack(message: OptionsAutomatorResponse) { | ||
const successBlock: KnownBlock[] = [ | ||
slackblocks.header( | ||
slackblocks.plaintext('✅ Successfully Updated Options: ✅') | ||
), | ||
slackblocks.divider(), | ||
slackblocks.section(slackblocks.markdown('*Channel updated options:* ')), | ||
slackblocks.SectionBlock( | ||
message.channel_updated_options.map((option) => | ||
slackblocks.markdown(`channel updated \`${option}\``) | ||
) | ||
), | ||
slackblocks.divider(), | ||
slackblocks.section(slackblocks.markdown('*Updated options:* ')), | ||
slackblocks.SectionBlock( | ||
message.updated_options.map((option) => | ||
slackblocks.markdown( | ||
`updated \`${option.option_name}\` with db value \`${option.db_value}\` and value \`${option.value}\`` | ||
) | ||
) | ||
), | ||
slackblocks.divider(), | ||
slackblocks.section(slackblocks.markdown('*Set Options:* ')), | ||
slackblocks.SectionBlock( | ||
message.set_options.map((option) => | ||
slackblocks.markdown( | ||
`Set \`${option.option_name}\` with value \`${option.option_value}\`` | ||
) | ||
) | ||
), | ||
slackblocks.divider(), | ||
slackblocks.section(slackblocks.markdown('*Unset Options:* ')), | ||
slackblocks.SectionBlock( | ||
message.unset_options.map((option) => | ||
slackblocks.markdown(`Unset \`${option}\``) | ||
) | ||
), | ||
]; | ||
|
||
const failedBlock: KnownBlock[] = [ | ||
slackblocks.header(slackblocks.plaintext('❌ FAILED TO UPDATE: ❌')), | ||
slackblocks.divider(), | ||
slackblocks.section(slackblocks.markdown('*DRIFTED OPTIONS:* ')), | ||
slackblocks.SectionBlock( | ||
message.drifted_options.map((option) => | ||
slackblocks.markdown(`\`${option}\` drifted.`) | ||
) | ||
), | ||
slackblocks.divider(), | ||
slackblocks.section(slackblocks.markdown('*FAILED:* ')), | ||
slackblocks.SectionBlock( | ||
message.error_options.map((option) => | ||
slackblocks.markdown( | ||
`FAILED TO UPDATE \`${option.option_name}\` \nREASON: \`${option.error_msg}\`` | ||
) | ||
) | ||
), | ||
slackblocks.divider(), | ||
slackblocks.section(slackblocks.markdown('*Set Options:* ')), | ||
slackblocks.SectionBlock( | ||
message.set_options.map((option) => | ||
slackblocks.markdown( | ||
`Set \`${option.option_name}\` with value \`${option.option_value}\`` | ||
) | ||
) | ||
), | ||
]; | ||
|
||
try { | ||
// @ts-ignore | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this here bc CI tests are yelling? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah pretty much |
||
await bolt.client.chat.postMessage({ | ||
blocks: successBlock, | ||
channel: FEED_OPTIONS_AUTOMATOR_CHANNEL_ID, | ||
unfurl_links: false, | ||
}); | ||
return await bolt.client.chat.postMessage({ | ||
kneeyo1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
blocks: failedBlock, | ||
channel: FEED_OPTIONS_AUTOMATOR_CHANNEL_ID, | ||
unfurl_links: false, | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CI tests are yelling bc it says it needs text, but
Shows that its not necessary, confused There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Verify which version of the module you're getting w/ Yarn. It's not showing the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like we'd need to bump There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I faintly recall needing to set text but it being ignored and just the blocks were shown. |
||
} catch (err) { | ||
console.log(err); | ||
kneeyo1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be good to add this to the above
section()
function.export function section(block: MrkdwnElement, fields: MrkdownElement[])
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since section is already being used by other functions rewriting it is probably out of scope, spoke with Hubert and trying to make either parameter optional just makes the code too messy and unreadable, so I'm going to keep it as two functions