Skip to content
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

Merged
merged 25 commits into from
Aug 8, 2023

Conversation

kneeyo1
Copy link
Contributor

@kneeyo1 kneeyo1 commented Jul 26, 2023

This is a work in progress associated with this pr . The configoptions script runs as part of a kubernetes deployment and I would like to post the logs from that script to slack.

Ideally, that linked script from sentry would send post requests to the webhook defined here, which then pushes it to slack.

todo: figure out env variables and the slack channel I'm pushing to

Comment on lines 94 to 97
blocks: failedBlock,
channel: FEED_OPTIONS_AUTOMATOR_CHANNEL_ID,
unfurl_links: false,
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI tests are yelling bc it says it needs text, but

export interface ChatPostMessageArguments extends WebAPICallOptions, TokenOverridable {
    channel: string;
    text?: string;
    as_user?: boolean;
    attachments?: MessageAttachment[];
    blocks?: (KnownBlock | Block)[];
    icon_emoji?: string;
    icon_url?: string;
    metadata?: MessageMetadata;
    link_names?: boolean;
    mrkdwn?: boolean;
    parse?: 'full' | 'none';
    reply_broadcast?: boolean;
    thread_ts?: string;
    unfurl_links?: boolean;
    unfurl_media?: boolean;
    username?: string;
}

Shows that its not necessary, confused

Copy link

Choose a reason for hiding this comment

The 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 ? in the CI window so you may be tethered to an older version where that wasn't optional.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we'd need to bump slack/web-api for this to pick up text as optional parameter:
https://github.com/slackapi/node-slack-sdk/releases/tag/%40slack%2Fweb-api%406.2.0

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

src/webhooks/options-automator/options-automator.ts Outdated Show resolved Hide resolved
];

try {
// @ts-ignore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this here bc CI tests are yelling?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah pretty much

export function section(block: MrkdwnElement): KnownBlock {
return {
type: 'section',
text: block,
};
}

export function SectionBlock(fields: MrkdwnElement[]): KnownBlock {
Copy link
Contributor

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[])

Copy link
Contributor Author

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

src/webhooks/options-automator/options-automator.ts Outdated Show resolved Hide resolved
Comment on lines 94 to 97
blocks: failedBlock,
channel: FEED_OPTIONS_AUTOMATOR_CHANNEL_ID,
unfurl_links: false,
});
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

@@ -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';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where did you pick this channel id?
#proj-options-automator seems to be C04URUC21C5

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

@@ -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];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like an autoformatting change I didn't make this change

src/webhooks/options-automator/options-automator.ts Outdated Show resolved Hide resolved
@kneeyo1 kneeyo1 marked this pull request as ready for review August 7, 2023 17:58
@codecov
Copy link

codecov bot commented Aug 7, 2023

Codecov Report

Patch coverage: 97.91% and project coverage change: +0.19% 🎉

Comparison is base (5448e7f) 85.15% compared to head (a889c6c) 85.34%.
Report is 10 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #554      +/-   ##
==========================================
+ Coverage   85.15%   85.34%   +0.19%     
==========================================
  Files          98      101       +3     
  Lines        2445     2539      +94     
  Branches      479      505      +26     
==========================================
+ Hits         2082     2167      +85     
- Misses        357      366       +9     
  Partials        6        6              
Files Changed Coverage Δ
...rc/webhooks/options-automator/options-automator.ts 97.43% <97.43%> (ø)
src/blocks/slackBlocks.ts 100.00% <100.00%> (ø)
src/config/index.ts 98.93% <100.00%> (+0.02%) ⬆️
src/webhooks/options-automator/index.ts 100.00% <100.00%> (ø)

... and 8 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@hubertdeng123 hubertdeng123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lot of codecov warnings, perhaps this could use more coverage?

],
"unregistered_options": [],
"invalid_type_options": []
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: newline

};
}

export function section(block?: MrkdwnElement, fields?: MrkdwnElement[]): KnownBlock {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're passing in undefined a lot to this function. I think it's a bit cleaner if an object is passed in instead, this makes it more readable, especially when this function is called.

Suggested change
export function section(block?: MrkdwnElement, fields?: MrkdwnElement[]): KnownBlock {
export function section({ block, fields }): KnownBlock {

fields: fields,
};
} else {
throw new Error('Either block or fields must be provided.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like this error should be thrown before undefined is passed in for both block and fields here.

@kneeyo1 kneeyo1 merged commit fc57001 into main Aug 8, 2023
7 checks passed
@kneeyo1 kneeyo1 deleted the kneeyo1/options-automator-webhook branch August 8, 2023 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants