Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

feat: read from env #639

Merged
merged 7 commits into from
Aug 26, 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
15 changes: 14 additions & 1 deletion src/bindings/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import ms from "ms";

import { BotConfig, BotConfigSchema } from "../types";
import { DEFAULT_BOT_DELAY, DEFAULT_DISQUALIFY_TIME, DEFAULT_FOLLOWUP_TIME, DEFAULT_PERMIT_BASE_URL } from "../configs";
import {
DEFAULT_BOT_DELAY,
DEFAULT_DISQUALIFY_TIME,
DEFAULT_FOLLOWUP_TIME,
DEFAULT_PERMIT_BASE_URL,
DEFAULT_TIME_RANGE_FOR_MAX_ISSUE,
DEFAULT_TIME_RANGE_FOR_MAX_ISSUE_ENABLED,
} from "../configs";
import { getPayoutConfigByNetworkId } from "../helpers";
import { ajv } from "../utils";
import { Context } from "probot";
Expand Down Expand Up @@ -56,6 +63,12 @@ export const loadConfig = async (context: Context): Promise<BotConfig> => {
permitBaseUrl: process.env.PERMIT_BASE_URL || DEFAULT_PERMIT_BASE_URL,
},
unassign: {
timeRangeForMaxIssue: process.env.DEFAULT_TIME_RANGE_FOR_MAX_ISSUE
? Number(process.env.DEFAULT_TIME_RANGE_FOR_MAX_ISSUE)
: DEFAULT_TIME_RANGE_FOR_MAX_ISSUE,
timeRangeForMaxIssueEnabled: process.env.DEFAULT_TIME_RANGE_FOR_MAX_ISSUE_ENABLED
? process.env.DEFAULT_TIME_RANGE_FOR_MAX_ISSUE_ENABLED == "true"
: DEFAULT_TIME_RANGE_FOR_MAX_ISSUE_ENABLED,
followUpTime: ms(process.env.FOLLOW_UP_TIME || DEFAULT_FOLLOWUP_TIME),
disqualifyTime: ms(process.env.DISQUALIFY_TIME || DEFAULT_DISQUALIFY_TIME),
},
Expand Down
1 change: 1 addition & 0 deletions src/configs/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const COLORS = {
export const DEFAULT_BOT_DELAY = 100; // 100ms
export const DEFAULT_TIME_RANGE_FOR_MAX_ISSUE = 24;
export const DEFAULT_TIME_RANGE_FOR_MAX_ISSUE_ENABLED = true;

export const ASSIGN_COMMAND_ENABLED = true;
/**
* ms('2 days') // 172800000
Expand Down
10 changes: 6 additions & 4 deletions src/helpers/issue.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Context } from "probot";
import { getBotContext, getLogger } from "../bindings";
import { getBotContext, getLogger, loadConfig } from "../bindings";
import { AssignEvent, Comment, IssueType, Payload } from "../types";
import { checkRateLimitGit } from "../utils";
import { DEFAULT_TIME_RANGE_FOR_MAX_ISSUE, DEFAULT_TIME_RANGE_FOR_MAX_ISSUE_ENABLED } from "../configs";

export const clearAllPriceLabelsOnIssue = async (): Promise<void> => {
const context = getBotContext();
const logger = getLogger();
const payload = context.payload as Payload;

if (!payload.issue) return;

const labels = payload.issue.labels;
Expand Down Expand Up @@ -632,8 +632,10 @@ export const getCommitsOnPullRequest = async (pullNumber: number) => {
};

export const getAvailableOpenedPullRequests = async (username: string) => {
if (!DEFAULT_TIME_RANGE_FOR_MAX_ISSUE_ENABLED) return [];
const context = getBotContext();
const botConfig = await loadConfig(context);
EtherealGlow marked this conversation as resolved.
Show resolved Hide resolved
if (!botConfig.unassign.timeRangeForMaxIssueEnabled) return [];

const opened_prs = await getOpenedPullRequests(username);

const result = [];
Expand All @@ -647,7 +649,7 @@ export const getAvailableOpenedPullRequests = async (username: string) => {
if (approvedReviews) result.push(pr);
}

if (reviews.length === 0 && (new Date().getTime() - new Date(pr.created_at).getTime()) / (1000 * 60 * 60) >= DEFAULT_TIME_RANGE_FOR_MAX_ISSUE) {
if (reviews.length === 0 && (new Date().getTime() - new Date(pr.created_at).getTime()) / (1000 * 60 * 60) >= botConfig.unassign.timeRangeForMaxIssue) {
result.push(pr);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export const PayoutConfigSchema = Type.Object({
export const UnassignConfigSchema = Type.Object({
followUpTime: Type.Number(),
disqualifyTime: Type.Number(),
timeRangeForMaxIssue: Type.Number(),
timeRangeForMaxIssueEnabled: Type.Boolean(),
});

export const ModeSchema = Type.Object({
Expand Down