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

Move some values to constants #445

Merged
merged 2 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/brain/issueLabelHandler/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ import * as Sentry from '@sentry/node';
import moment from 'moment-timezone';

import {
BACKLOG_LABEL,
IN_PROGRESS_LABEL,
OFFICE_TIME_ZONES,
OFFICES_24_HOUR,
PRODUCT_AREA_LABEL_PREFIX,
SENTRY_ORG,
STATUS_LABEL_PREFIX,
UNKNOWN_LABEL,
UNROUTED_LABEL,
UNTRIAGED_LABEL,
} from '@/config';
import {
calculateSLOViolationRoute,
Expand All @@ -18,11 +24,9 @@ import { getOssUserType } from '@utils/getOssUserType';
import { isFromABot } from '@utils/isFromABot';
import { slugizeProductArea } from '@utils/slugizeProductArea';

const LENGTH_OF_PRODUCT_AREA_LABEL_PREFIX = 14;
const REPOS_TO_TRACK_FOR_ROUTING = new Set(['sentry', 'sentry-docs']);

import { ClientType } from '@/api/github/clientType';
import { UNROUTED_LABEL, UNTRIAGED_LABEL } from '@/config';
import { getClient } from '@api/github/getClient';

// Validation Helpers
Expand Down Expand Up @@ -59,16 +63,18 @@ function isValidLabel(payload) {
!payload.label?.name.startsWith(PRODUCT_AREA_LABEL_PREFIX) ||
payload.issue.labels?.some(
(label) =>
label.name === 'Status: Backlog' || label.name === 'Status: In Progress'
label.name === BACKLOG_LABEL || label.name === IN_PROGRESS_LABEL
) ||
payload.issue.state !== 'open'
);
}

function shouldLabelBeRemoved(label, target_name) {
return (
(label.name.startsWith('Product Area: ') && label.name !== target_name) ||
(label.name.startsWith('Status: ') && label.name !== UNTRIAGED_LABEL)
(label.name.startsWith(PRODUCT_AREA_LABEL_PREFIX) &&
label.name !== target_name) ||
(label.name.startsWith(STATUS_LABEL_PREFIX) &&
label.name !== UNTRIAGED_LABEL)
);
}

Expand Down Expand Up @@ -105,7 +111,7 @@ export async function markUnrouted({

const timeToRouteBy = await calculateSLOViolationRoute(UNROUTED_LABEL);
const { readableDueByDate, lastOfficeInBusinessHours } =
await getReadableTimeStamp(timeToRouteBy, 'Product Area: Unknown');
await getReadableTimeStamp(timeToRouteBy, UNKNOWN_LABEL);
await octokit.issues.createComment({
owner,
repo: payload.repository.name,
Expand All @@ -119,7 +125,7 @@ export async function markUnrouted({
async function routeIssue(octokit, productAreaLabelName) {
try {
const productArea = productAreaLabelName?.substr(
LENGTH_OF_PRODUCT_AREA_LABEL_PREFIX
PRODUCT_AREA_LABEL_PREFIX.length
);
const ghTeamSlug = 'product-owners-' + slugizeProductArea(productArea);
await octokit.teams.getByName({
Expand Down
4 changes: 4 additions & 0 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,12 @@ export enum BuildStatus {
* GitHub Triage
*/
export const PRODUCT_AREA_LABEL_PREFIX = 'Product Area: ';
export const STATUS_LABEL_PREFIX = 'Status: ';
export const BACKLOG_LABEL = 'Status: Backlog';
export const IN_PROGRESS_LABEL = 'Status: In Progress';
export const UNTRIAGED_LABEL = 'Status: Untriaged';
export const UNROUTED_LABEL = 'Status: Unrouted';
export const UNKNOWN_LABEL = 'Status: Unknown';
chadwhitacre marked this conversation as resolved.
Show resolved Hide resolved
export const MAX_TRIAGE_DAYS = 2;
export const MAX_ROUTE_DAYS = 1;

Expand Down