Skip to content
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
21 changes: 4 additions & 17 deletions create-node-meeting-artifacts.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,6 @@ const meetingTitle = meetings.generateMeetingTitle(
meetingDate
);

// Look for existing issues
if (!config.force) {
const existingIssue = await github.findIssueByTitle(
githubClient,
meetingTitle,
meetingConfig
);

if (existingIssue) {
console.log(`${existingIssue.html_url} already exists. Exiting.`);
process.exit(0);
}
}

// Step 9: Get agenda information using native implementation
const gitHubAgendaIssues = await github.getAgendaIssues(
githubClient,
Expand All @@ -103,10 +89,10 @@ const gitHubAgendaIssues = await github.getAgendaIssues(
const meetingAgenda = meetings.generateMeetingAgenda(gitHubAgendaIssues);

// Step 11: Create HackMD document with meeting notes and tags
const hackmdNote = await hackmd.createMeetingNotesDocument(
const hackmdNote = await hackmd.getOrCreateMeetingNotesDocument(
hackmdClient,
meetingTitle,
''
config
);

// Step 12: Get the HackMD document link
Expand All @@ -123,8 +109,9 @@ const issueContent = await meetings.generateMeetingIssue(
);

// Step 14: Create GitHub issue with HackMD link
const githubIssue = await github.createGitHubIssue(
const githubIssue = await github.createOrUpdateGitHubIssue(
githubClient,
config,
meetingConfig,
meetingTitle,
issueContent
Expand Down
69 changes: 68 additions & 1 deletion src/github.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,46 @@ export const createGitHubIssue = async (
return response.data;
};

/**
* Creates or updates a GitHub issue with meeting information and Google Doc link
* @param {import('@octokit/rest').Octokit} githubClient - Authenticated GitHub API client
* @param {import('./types.d.ts').AppConfig} config - The application config
* @param {import('./types.d.ts').MeetingConfig} meetingConfig - Meeting configuration object
* @param {string} title - Issue title
* @param {string} content - Issue content
* @returns {Promise<GitHubIssue>} Created issue data
*/
export const createOrUpdateGitHubIssue = async (
githubClient,
{ force },
meetingConfig,
title,
content
) => {
if (!force) {
const existingIssue = await findGitHubIssueByTitle(
githubClient,
title,
meetingConfig
);

if (existingIssue) {
if (content !== existingIssue.body) {
await updateGitHubIssue(
githubClient,
existingIssue.number,
content,
meetingConfig
);
}

return existingIssue;
}
}

return createGitHubIssue(githubClient, meetingConfig, title, content);
};

/**
* Sorts issues by repository
* @param {Array<GitHubIssue>} issues The issues to sort
Expand All @@ -55,13 +95,40 @@ export const sortIssuesByRepo = issues =>
return obj;
}, {});

/**
* Updates an existing GitHub issue with new content
* @param {import('@octokit/rest').Octokit} githubClient - Authenticated GitHub API client
* @param {number} number - The issue number
* @param {string} content - The new content
* @param {import('./types.d.ts').MeetingConfig} meetingConfig - Meeting configuration
*/
export const updateGitHubIssue = async (
githubClient,
number,
content,
{ properties }
) => {
const githubOrg = properties.USER ?? DEFAULT_CONFIG.githubOrg;

return githubClient.issues.update({
issue_number: number,
body: content,
owner: githubOrg,
repo: properties.REPO,
});
};

/**
* Fetches GitHub issue from a repo with a given title
* @param {import('@octokit/rest').Octokit} githubClient - Authenticated GitHub API client
* @param {string} title - The title to find
* @param {import('./types.d.ts').MeetingConfig} meetingConfig - Meeting configuration
*/
export const findIssueByTitle = async (githubClient, title, { properties }) => {
export const findGitHubIssueByTitle = async (
githubClient,
title,
{ properties }
) => {
const githubOrg = properties.USER ?? DEFAULT_CONFIG.githubOrg;

const issues = await githubClient.request('GET /search/issues', {
Expand Down
24 changes: 24 additions & 0 deletions src/hackmd.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,30 @@ export const createMeetingNotesDocument = (hackmdClient, title, content) => {
.then(response => response?.note ?? response);
};

/**
* Creates a new meeting notes document in HackMD with appropriate tags
* @param {HackMDAPI} hackmdClient - HackMD API client
* @param {string} title - Document title
* @param {import('./types.d.ts').AppConfig} config - Configuration
* @returns {Promise<HackMDNote>} The created / fetched note
*/
export const getOrCreateMeetingNotesDocument = async (
hackmdClient,
title,
{ force }
) => {
if (!force) {
const notes = await hackmdClient.getNoteList();
const existingNote = notes.find(note => note.title === title);

if (existingNote) {
return existingNote;
}
}

return createMeetingNotesDocument(hackmdClient, title, '');
};

/**
* Updates an existing meeting notes document in HackMD with retry logic
* @param {HackMDClient} hackmdClient - HackMD API client
Expand Down
Loading