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

feat: add weekly report #49

Merged
merged 3 commits into from
Aug 2, 2024
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
6 changes: 0 additions & 6 deletions .idea/biome.xml

This file was deleted.

5 changes: 0 additions & 5 deletions .idea/codeStyles/codeStyleConfig.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

72 changes: 72 additions & 0 deletions packages/github/src/client/GitHub.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
filterPullRequestsAsIssues,
} from "../filters/issues.mjs";
import { issueSchema, issueSearchSchema } from "../schemas/issues.mjs";
import { milestoneSchema } from "../schemas/milestones.mjs";
import { pullRequestSchema } from "../schemas/pull_requests.mjs";

export class GitHub {
Expand Down Expand Up @@ -133,6 +134,8 @@ export class GitHub {
* @param {number} [options.minDaysOld] - The minimum number of days since the issue was created.
* @param {number} [options.minDaysWithoutUpdate] - The minimum number of days since the issue was last updated.
* @param {string[]} [options.excludeLabels] - Exclude issues containing these labels
* @param {number} [options.milestone] - Milestone number to filter issues by
* @param {("open" | "closed" | "all")} [options.state="open"] - Limit listing to issues in these state
*
* @example List feature requests, excluding blocked issues
*
Expand All @@ -157,6 +160,8 @@ export class GitHub {
excludeLabels = [],
minDaysOld,
minDaysWithoutUpdate,
milestone,
state = "open",
} = options;

let issues = [];
Expand All @@ -178,6 +183,8 @@ export class GitHub {
sort: sortBy,
direction,
per_page: pageSize,
milestone,
state,
})) {
let filteredIssues = ret;

Expand Down Expand Up @@ -391,4 +398,69 @@ export class GitHub {
state,
});
}

/**
* List milestones
*
* @param {Object} options - Config.
* @param {("open" | "closed" | "all")} [options.state] - Include milestones in these states
* @param {("due_on" | "completeness")} [options.sortBy] - Sort results by
* @param {number} [options.limit] - Max number of issues to return (default 10)
* @param {number} [options.pageSize] - Pagination size for each List Issues API call (max 100)
* @param {("asc" | "desc")} [options.direction] - Results direction (default ascending)
*
* @example List open milestones
*
* ```javascript
* const github = new GitHub();
* const issues = await github.listIssues({
* state: 'open',
* sortBy: 'due_on',
* });
* ```
* @returns {Promise<z.infer<typeof milestoneSchema>[]>} Milestone
*/
async listMilestones(options = {}) {
const {
sortBy,
limit = MAX_ISSUES_LIMIT,
pageSize = MAX_ISSUES_PER_PAGE,
direction = "asc",
state = "all",
} = options;

let milestones = [];

try {
this.logger.info("Listing issues. Filtered by state", {
sortBy: sortBy,
state,
limit: limit,
});

// fetch as many milestones as possible (`pageSize`), cap the results (`limit`)
for await (const { data: ret } of this.client.paginate.iterator(this.client.rest.issues.listMilestones, {
owner: this.owner,
repo: this.repo,
state,
sort: sortBy,
direction,
per_page: pageSize,
})) {
milestones.push(...ret);

if (milestones.length >= limit) {
milestones = milestones.slice(0, limit);
break;
}
}

this.logger.debug("Milestones", { milestones });

return milestones;
} catch (error) {
this.logger.error("Unable to list milestones", error);
throw error;
}
}
}
51 changes: 51 additions & 0 deletions packages/github/src/schemas/milestones.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { z } from "zod";

export const milestoneSchema = z.array(
z
.object({
url: z.string().url(),
html_url: z.string().url(),
labels_url: z.string().url(),
id: z.number().int(),
node_id: z.string(),
number: z.number().int().describe("The number of the milestone."),
state: z.enum(["open", "closed"]).describe("The state of the milestone."),
title: z.string().describe("The title of the milestone."),
description: z.union([z.string(), z.null()]),
creator: z.union([
z.null(),
z
.object({
name: z.union([z.string(), z.null()]).optional(),
email: z.union([z.string(), z.null()]).optional(),
login: z.string(),
id: z.number().int(),
node_id: z.string(),
avatar_url: z.string().url(),
gravatar_id: z.union([z.string(), z.null()]),
url: z.string().url(),
html_url: z.string().url(),
followers_url: z.string().url(),
following_url: z.string(),
gists_url: z.string(),
starred_url: z.string(),
subscriptions_url: z.string().url(),
organizations_url: z.string().url(),
repos_url: z.string().url(),
events_url: z.string(),
received_events_url: z.string().url(),
type: z.string(),
site_admin: z.boolean(),
starred_at: z.string().optional(),
})
.describe("A GitHub user."),
]),
open_issues: z.number().int(),
closed_issues: z.number().int(),
created_at: z.string(),
updated_at: z.string(),
closed_at: z.union([z.string(), z.null()]),
due_on: z.union([z.string(), z.null()]),
})
.describe("A collection of related issues and pull requests."),
);
33 changes: 33 additions & 0 deletions packages/github/types/client/GitHub.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ export class GitHub {
* @param {number} [options.minDaysOld] - The minimum number of days since the issue was created.
* @param {number} [options.minDaysWithoutUpdate] - The minimum number of days since the issue was last updated.
* @param {string[]} [options.excludeLabels] - Exclude issues containing these labels
* @param {number} [options.milestone] - Milestone number to filter issues by
* @param {("open" | "closed" | "all")} [options.state="open"] - Limit listing to issues in these state
*
* @example List feature requests, excluding blocked issues
*
Expand All @@ -92,6 +94,8 @@ export class GitHub {
minDaysOld?: number;
minDaysWithoutUpdate?: number;
excludeLabels?: string[];
milestone?: number;
state?: ("open" | "closed" | "all");
}): Promise<z.infer<typeof issueSchema>[]>;
/**
* Searches for an issue based on query parameters.
Expand Down Expand Up @@ -545,11 +549,40 @@ export class GitHub {
state?: ("open" | "closed");
milestone?: number;
}): Promise<z.infer<typeof issueSchema>>;
/**
* List milestones
*
* @param {Object} options - Config.
* @param {("open" | "closed" | "all")} [options.state] - Include milestones in these states
* @param {("due_on" | "completeness")} [options.sortBy] - Sort results by
* @param {number} [options.limit] - Max number of issues to return (default 10)
* @param {number} [options.pageSize] - Pagination size for each List Issues API call (max 100)
* @param {("asc" | "desc")} [options.direction] - Results direction (default ascending)
*
* @example List open milestones
*
* ```javascript
* const github = new GitHub();
* const issues = await github.listIssues({
* state: 'open',
* sortBy: 'due_on',
* });
* ```
* @returns {Promise<z.infer<typeof milestoneSchema>[]>} Milestone
*/
listMilestones(options?: {
state?: ("open" | "closed" | "all");
sortBy?: ("due_on" | "completeness");
limit?: number;
pageSize?: number;
direction?: ("asc" | "desc");
}): Promise<z.infer<typeof milestoneSchema>[]>;
#private;
}
import { Logger } from "@aws-lambda-powertools/logger";
import { z } from "zod";
import { pullRequestSchema } from "../schemas/pull_requests.mjs";
import { issueSchema } from "../schemas/issues.mjs";
import { milestoneSchema } from "../schemas/milestones.mjs";
import { Octokit } from "@octokit/rest";
//# sourceMappingURL=GitHub.d.mts.map
2 changes: 1 addition & 1 deletion packages/github/types/client/GitHub.d.mts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading