mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-09 11:12:52 +00:00
refactor: split api into api, api-cli & api-plugin
This commit is contained in:
@@ -31,7 +31,7 @@
|
||||
"@openstapps/logger": "workspace:*",
|
||||
"@slack/web-api": "6.8.1",
|
||||
"commander": "10.0.0",
|
||||
"date-fns": "2.29.3",
|
||||
"date-fns": "2.30.0",
|
||||
"glob": "10.2.6",
|
||||
"mustache": "4.2.0"
|
||||
},
|
||||
@@ -52,7 +52,7 @@
|
||||
"mocha": "10.2.0",
|
||||
"ts-node": "10.9.1",
|
||||
"tsup": "6.7.0",
|
||||
"typescript": "4.8.4"
|
||||
"typescript": "4.9.5"
|
||||
},
|
||||
"tsup": {
|
||||
"entry": [
|
||||
|
||||
@@ -17,7 +17,6 @@ import {Logger} from '@openstapps/logger';
|
||||
|
||||
/**
|
||||
* Get projects for a list of groups
|
||||
*
|
||||
* @param api GitLab API to make requests with
|
||||
* @param groups List of groups
|
||||
*/
|
||||
|
||||
@@ -18,7 +18,6 @@ import {readFile} from 'fs/promises';
|
||||
|
||||
/**
|
||||
* Get used version of a dependency of a project referenced by a path
|
||||
*
|
||||
* @param directoryPath Path to a Node.js project directory
|
||||
* @param dependency Dependency to get used version of
|
||||
*/
|
||||
@@ -46,7 +45,6 @@ export async function getUsedVersion(directoryPath: PathLike, dependency: string
|
||||
* Get 'MAJOR.MINOR' part of a used version
|
||||
*
|
||||
* See [[getUsedVersion]].
|
||||
*
|
||||
* @param path see [[getUsedVersion]]
|
||||
* @param dependency see [[getUsedVersion]]
|
||||
*/
|
||||
|
||||
@@ -27,7 +27,6 @@ import {GROUPS, MAX_DEPTH_FOR_REMINDER, NOTE_PREFIX, SLACK_CHANNEL} from '../con
|
||||
|
||||
/**
|
||||
* Remind people of open merge requests
|
||||
*
|
||||
* @param api GitLab API to make requests with
|
||||
*/
|
||||
export async function remind(api: Api): Promise<void> {
|
||||
@@ -54,9 +53,7 @@ export async function remind(api: Api): Promise<void> {
|
||||
|
||||
// instantiate slack client
|
||||
const client =
|
||||
typeof process.env.SLACK_API_TOKEN === 'undefined'
|
||||
? undefined
|
||||
: new WebClient(process.env.SLACK_API_TOKEN);
|
||||
process.env.SLACK_API_TOKEN === undefined ? undefined : new WebClient(process.env.SLACK_API_TOKEN);
|
||||
|
||||
// get members of main group
|
||||
const members = await api.getMembers(MembershipScope.GROUPS, GROUPS[0]);
|
||||
@@ -92,14 +89,14 @@ export async function remind(api: Api): Promise<void> {
|
||||
// check if at least one of the discussions is unresolved
|
||||
const hasUnresolvedDiscussions = discussions.some(discussion => {
|
||||
return discussion.notes.some(note => {
|
||||
return note.resolvable && (typeof note.resolved === 'undefined' || !note.resolved);
|
||||
return note.resolvable && (note.resolved === undefined || !note.resolved);
|
||||
});
|
||||
});
|
||||
|
||||
if (hasUnresolvedDiscussions) {
|
||||
let recipient = mergeRequest.author.username;
|
||||
|
||||
if (typeof mergeRequest.assignee !== 'undefined' && mergeRequest.assignee !== null) {
|
||||
if (mergeRequest.assignee !== undefined && mergeRequest.assignee !== null) {
|
||||
recipient = mergeRequest.assignee.username;
|
||||
}
|
||||
|
||||
|
||||
@@ -146,7 +146,6 @@ export interface MergeRequestsForProjects {
|
||||
|
||||
/**
|
||||
* Check if issue state is opened or closed
|
||||
*
|
||||
* @param state State to check
|
||||
*/
|
||||
export function issueStateIsOpenedOrClosed(
|
||||
@@ -157,7 +156,6 @@ export function issueStateIsOpenedOrClosed(
|
||||
|
||||
/**
|
||||
* Get merge request URLs from given data
|
||||
*
|
||||
* @param projectMergeRequests Merge requests data (object containing array of objects)
|
||||
* @param projectId Project ID to get data about merge requests for
|
||||
* @param issueIid Issue IID in certain project (relative ID, and not issue's GitLab API ID)
|
||||
@@ -167,10 +165,7 @@ export function getMergeRequestUrls(
|
||||
projectId: number,
|
||||
issueIid: number,
|
||||
): string[] {
|
||||
if (
|
||||
typeof projectMergeRequests[projectId] === 'undefined' ||
|
||||
projectMergeRequests[projectId].length === 0
|
||||
) {
|
||||
if (projectMergeRequests[projectId] === undefined || projectMergeRequests[projectId].length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -185,7 +180,6 @@ export function getMergeRequestUrls(
|
||||
|
||||
/**
|
||||
* Get issues from all groups with a specific milestone
|
||||
*
|
||||
* @param api GitLab API to make requests with
|
||||
* @param label Label to filter by
|
||||
* @param groups List of groups to get issues for
|
||||
@@ -210,7 +204,6 @@ export async function getIssues(api: Api, label: string, groups: number[]): Prom
|
||||
|
||||
/**
|
||||
* Get IDs of issues with branches for projects
|
||||
*
|
||||
* @param api GitLab API To make requests with
|
||||
* @param projects List of projects
|
||||
*/
|
||||
@@ -240,7 +233,6 @@ export async function getIssueBranches(api: Api, projects: Project[]): Promise<{
|
||||
|
||||
/**
|
||||
* Get issues grouped by assignees
|
||||
*
|
||||
* @param api GitLab API to make requests with
|
||||
* @param label Label to generate report for
|
||||
*/
|
||||
@@ -269,7 +261,7 @@ export async function getIssuesGroupedByAssignees(api: Api, label: string): Prom
|
||||
continue;
|
||||
}
|
||||
|
||||
if (typeof issuesByAssignee[issue.assignee.id] === 'undefined') {
|
||||
if (issuesByAssignee[issue.assignee.id] === undefined) {
|
||||
issuesByAssignee[issue.assignee.id] = {
|
||||
assignee: issue.assignee,
|
||||
issueCounts: {
|
||||
@@ -287,8 +279,7 @@ export async function getIssuesGroupedByAssignees(api: Api, label: string): Prom
|
||||
|
||||
const issueMeta = {
|
||||
$branchExists:
|
||||
typeof issueBranches[issue.project_id] !== 'undefined' &&
|
||||
issueBranches[issue.project_id].includes(issue.iid),
|
||||
issueBranches[issue.project_id] !== undefined && issueBranches[issue.project_id].includes(issue.iid),
|
||||
$closed: issue.state === IssueState.CLOSED,
|
||||
$issue: issue,
|
||||
$labels: issue.labels.map((issueLabel: string) => {
|
||||
@@ -387,7 +378,6 @@ export function getNextMeetingDay() {
|
||||
|
||||
/**
|
||||
* Get a list of merge requests for projects
|
||||
*
|
||||
* @param api GitLab API to make requests with
|
||||
* @param projects List of projects
|
||||
*/
|
||||
@@ -432,7 +422,6 @@ export async function getMergeRequests(api: Api, projects: Project[]): Promise<M
|
||||
|
||||
/**
|
||||
* Generate a report
|
||||
*
|
||||
* @param api GitLab API to make requests with
|
||||
* @param label Label to generate report for
|
||||
* @param template Template to generate report with
|
||||
@@ -451,7 +440,6 @@ export async function generateReport(api: Api, label: string, template: string):
|
||||
|
||||
/**
|
||||
* Generate a markdown report
|
||||
*
|
||||
* @param api GitLab API to make requests with
|
||||
* @param label Label to generate report for
|
||||
*/
|
||||
|
||||
@@ -37,7 +37,6 @@ import {
|
||||
* Tidy issues without milestone
|
||||
*
|
||||
* This will set the milestone of issues without milestone to 'Meeting'.
|
||||
*
|
||||
* @param api GitLab API instance to use for the requests
|
||||
*/
|
||||
export async function tidyIssuesWithoutMilestone(api: Api): Promise<void> {
|
||||
@@ -58,7 +57,7 @@ export async function tidyIssuesWithoutMilestone(api: Api): Promise<void> {
|
||||
|
||||
await Promise.all(
|
||||
issuesWithoutMilestone.map(async issue => {
|
||||
if (typeof milestoneCache[issue.project_id] === 'undefined') {
|
||||
if (milestoneCache[issue.project_id] === undefined) {
|
||||
milestoneCache[issue.project_id] = await api.getMilestonesForProject(issue.project_id);
|
||||
}
|
||||
|
||||
@@ -70,7 +69,7 @@ export async function tidyIssuesWithoutMilestone(api: Api): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof milestoneId === 'undefined') {
|
||||
if (milestoneId === undefined) {
|
||||
Logger.warn(`Milestone 'Meeting' was not available for issue ${issue.title} (${issue.web_url}).`);
|
||||
|
||||
return;
|
||||
@@ -96,7 +95,6 @@ export async function tidyIssuesWithoutMilestone(api: Api): Promise<void> {
|
||||
* Tidy open issues without meeting label
|
||||
*
|
||||
* This adds the label 'meeting' to all open issues that do not have this label.
|
||||
*
|
||||
* @param api GitLab API instante to use for requests
|
||||
*/
|
||||
export async function tidyOpenIssuesWithoutMeetingLabel(api: Api): Promise<void> {
|
||||
@@ -141,7 +139,6 @@ export async function tidyOpenIssuesWithoutMeetingLabel(api: Api): Promise<void>
|
||||
|
||||
/**
|
||||
* Tidy labels in a list of projects
|
||||
*
|
||||
* @param api GitLab API instance to use for the requests
|
||||
* @param projects List of projects to tidy labels on
|
||||
*/
|
||||
@@ -189,7 +186,6 @@ export async function tidyLabels(api: Api, projects: Project[]): Promise<void> {
|
||||
|
||||
/**
|
||||
* Tidy milestones in a list of projects
|
||||
*
|
||||
* @param api GitLab API instance to use for the requests
|
||||
* @param projects List of projects to tidy milestones on
|
||||
*/
|
||||
@@ -223,7 +219,6 @@ export async function tidyMilestones(api: Api, projects: Project[]): Promise<voi
|
||||
|
||||
/**
|
||||
* Tidy protected branches in a list of projects
|
||||
*
|
||||
* @param api GitLab API instance to use for the requests
|
||||
* @param projects List of projects to tidy milestones on
|
||||
*/
|
||||
@@ -257,7 +252,6 @@ export async function tidyProtectedBranches(api: Api, projects: Project[]): Prom
|
||||
|
||||
/**
|
||||
* Tidy protected tags
|
||||
*
|
||||
* @param api GitLab API instance to use for the requests
|
||||
* @param projects List of projects to tidy protected tags on
|
||||
*/
|
||||
@@ -310,7 +304,6 @@ export async function tidyProtectedTags(api: Api, projects: Project[]): Promise<
|
||||
|
||||
/**
|
||||
* Tidy "sub" group members
|
||||
*
|
||||
* @param api GitLab API instance to use for the requests
|
||||
*/
|
||||
export async function tidySubGroupMembers(api: Api): Promise<void> {
|
||||
@@ -357,7 +350,6 @@ export async function tidySubGroupMembers(api: Api): Promise<void> {
|
||||
* Tidy issues without assignee
|
||||
*
|
||||
* Set assignee to author if no assignee is set.
|
||||
*
|
||||
* @param api GitLab API instance to use for the requests
|
||||
*/
|
||||
export async function tidyIssuesWithoutAssignee(api: Api): Promise<void> {
|
||||
@@ -399,7 +391,6 @@ export async function tidyIssuesWithoutAssignee(api: Api): Promise<void> {
|
||||
* Tidy merge requests without assignee
|
||||
*
|
||||
* Set assignee to author if no assignee is set.
|
||||
*
|
||||
* @param api GitLab API instance to use for the requests
|
||||
*/
|
||||
export async function tidyMergeRequestsWithoutAssignee(api: Api): Promise<void> {
|
||||
@@ -435,7 +426,6 @@ export async function tidyMergeRequestsWithoutAssignee(api: Api): Promise<void>
|
||||
|
||||
/**
|
||||
* Tidy
|
||||
*
|
||||
* @param api GitLab API instance to use for the requests
|
||||
*/
|
||||
export async function tidy(api: Api) {
|
||||
|
||||
@@ -19,7 +19,6 @@ import isBefore from 'date-fns/isBefore';
|
||||
|
||||
/**
|
||||
* Remove label `meeting` from closed issues
|
||||
*
|
||||
* @param api Instance of GitLabAPI to send requests with
|
||||
*/
|
||||
export async function unlabel(api: Api) {
|
||||
|
||||
Reference in New Issue
Block a user