Skip to content

Commit 8363149

Browse files
avivkellerovflowd
authored andcommitted
use helper
1 parent b4978cb commit 8363149

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

src/constants.mjs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,3 @@ export const HACKMD_DEFAULT_PERMISSIONS = {
3434
writePermission: 'signed_in',
3535
commentPermission: 'signed_in_users',
3636
};
37-
38-
export const REPOSITORY_URL_PREFIX_LENGTH = 'https://api.github.com/repos/'
39-
.length;

src/github.mjs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Octokit } from '@octokit/rest';
22

3-
import { DEFAULT_CONFIG, REPOSITORY_URL_PREFIX_LENGTH } from './constants.mjs';
3+
import { DEFAULT_CONFIG } from './constants.mjs';
44

55
/**
66
* Creates a GitHub API client
@@ -42,12 +42,25 @@ export const createGitHubIssue = async (
4242
return response.data;
4343
};
4444

45+
/**
46+
* Sorts issues by repository
47+
* @param {Array<GitHubIssue>} issues The issues to sort
48+
* @returns {Promise<{ [key: string]: Array<GitHubIssue> }>} Sorted issues
49+
*/
50+
export const sortIssuesByRepo = issues =>
51+
issues.reduce((obj, issue) => {
52+
(obj[issue.repository_url.split('/').slice(-2).join('/')] ||= []).push(
53+
issue
54+
);
55+
return obj;
56+
}, {});
57+
4558
/**
4659
* Fetches GitHub issues from all repositories in an organization with a specific label
4760
* @param {import('@octokit/rest').Octokit} githubClient - Authenticated GitHub API client
4861
* @param {import('./types.d.ts').AppConfig} config - Application configuration
4962
* @param {import('./types.d.ts').MeetingConfig} meetingConfig - Meeting configuration
50-
* @returns {Promise<{ [key: string]: Array<GitHubIssue> }>} Formatted markdown string of issues
63+
* @returns {Promise<{ [key: string]: Array<GitHubIssue> }>} Meeting agenda
5164
*/
5265
export const getAgendaIssues = async (
5366
githubClient,
@@ -59,14 +72,9 @@ export const getAgendaIssues = async (
5972

6073
// Get all issues/PRs in the organization
6174
const issues = await githubClient.paginate('GET /search/issues', {
62-
q: `label:${agendaTag} org:${githubOrg}`,
75+
q: `is:open label:${agendaTag} org:${githubOrg}`,
6376
advanced_search: true,
6477
});
6578

66-
return issues.reduce((obj, issue) => {
67-
(obj[issue.repository_url.slice(REPOSITORY_URL_PREFIX_LENGTH)] ||= []).push(
68-
issue
69-
);
70-
return obj;
71-
}, {});
79+
return sortIssuesByRepo(issues);
7280
};

0 commit comments

Comments
 (0)