Address code review feedback: update actions versions, add org support, improve docs
Co-authored-by: blackboxprogramming <118287761+blackboxprogramming@users.noreply.github.com>
This commit is contained in:
13
.github/workflows/digest-bot.yml
vendored
13
.github/workflows/digest-bot.yml
vendored
@@ -20,10 +20,10 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: 🧬 Checkout Repo
|
- name: 🧬 Checkout Repo
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: 🧠 Set up Node
|
- name: 🧠 Set up Node
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 18
|
node-version: 18
|
||||||
|
|
||||||
@@ -35,8 +35,13 @@ jobs:
|
|||||||
node -e "
|
node -e "
|
||||||
const { runWeeklyDigest } = require('./bot/handlers/digest-bot.js');
|
const { runWeeklyDigest } = require('./bot/handlers/digest-bot.js');
|
||||||
|
|
||||||
const owner = process.env.GITHUB_REPOSITORY.split('/')[0];
|
const repoEnv = process.env.GITHUB_REPOSITORY;
|
||||||
const repo = process.env.GITHUB_REPOSITORY.split('/')[1];
|
if (!repoEnv || !repoEnv.includes('/')) {
|
||||||
|
console.error('❌ GITHUB_REPOSITORY environment variable is not set or invalid');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const [owner, repo] = repoEnv.split('/');
|
||||||
const digestIssueNumber = process.env.DIGEST_ISSUE_NUMBER ? parseInt(process.env.DIGEST_ISSUE_NUMBER) : null;
|
const digestIssueNumber = process.env.DIGEST_ISSUE_NUMBER ? parseInt(process.env.DIGEST_ISSUE_NUMBER) : null;
|
||||||
|
|
||||||
runWeeklyDigest(owner, repo, digestIssueNumber)
|
runWeeklyDigest(owner, repo, digestIssueNumber)
|
||||||
|
|||||||
@@ -7,6 +7,9 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches issues with reaction data from the repository.
|
* Fetches issues with reaction data from the repository.
|
||||||
|
* @param {string} owner - Repository owner (username or organization)
|
||||||
|
* @param {string} repo - Repository name
|
||||||
|
* @param {string} since - ISO 8601 date string to filter issues updated since this date
|
||||||
*/
|
*/
|
||||||
async function fetchIssuesWithReactions(owner, repo, since) {
|
async function fetchIssuesWithReactions(owner, repo, since) {
|
||||||
const token = process.env.GITHUB_TOKEN;
|
const token = process.env.GITHUB_TOKEN;
|
||||||
|
|||||||
@@ -107,16 +107,21 @@ async function getIssueNodeId(owner, repo, issueNumber) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches project fields and their options.
|
* Fetches project fields and their options.
|
||||||
|
* Supports both user and organization projects.
|
||||||
|
* @param {string} owner - The user or organization login
|
||||||
|
* @param {number} projectNumber - The project number
|
||||||
|
* @param {boolean} isOrg - Whether the owner is an organization (default: false)
|
||||||
*/
|
*/
|
||||||
async function getProjectFields(owner, projectNumber) {
|
async function getProjectFields(owner, projectNumber, isOrg = false) {
|
||||||
const token = process.env.GITHUB_TOKEN;
|
const token = process.env.GITHUB_TOKEN;
|
||||||
if (!token) {
|
if (!token) {
|
||||||
throw new Error("GITHUB_TOKEN environment variable is not set");
|
throw new Error("GITHUB_TOKEN environment variable is not set");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ownerType = isOrg ? "organization" : "user";
|
||||||
const query = `
|
const query = `
|
||||||
query GetProjectFields($owner: String!, $projectNumber: Int!) {
|
query GetProjectFields($owner: String!, $projectNumber: Int!) {
|
||||||
user(login: $owner) {
|
${ownerType}(login: $owner) {
|
||||||
projectV2(number: $projectNumber) {
|
projectV2(number: $projectNumber) {
|
||||||
id
|
id
|
||||||
fields(first: 20) {
|
fields(first: 20) {
|
||||||
@@ -162,7 +167,7 @@ async function getProjectFields(owner, projectNumber) {
|
|||||||
throw new Error(`GraphQL errors: ${JSON.stringify(data.errors)}`);
|
throw new Error(`GraphQL errors: ${JSON.stringify(data.errors)}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return data.data.user.projectV2;
|
return data.data[ownerType].projectV2;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|||||||
@@ -6,9 +6,6 @@ const event = process.env.GITHUB_EVENT_PATH;
|
|||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const { updateProjectField, getIssueNodeId } = require("./handlers/project-graphql-updater");
|
const { updateProjectField, getIssueNodeId } = require("./handlers/project-graphql-updater");
|
||||||
|
|
||||||
// Load configuration
|
|
||||||
const configPath = process.env.EMOJI_BOT_CONFIG || "../emoji-bot-config.yml";
|
|
||||||
|
|
||||||
// Mapping of reaction content to status updates
|
// Mapping of reaction content to status updates
|
||||||
const REACTION_TO_STATUS = {
|
const REACTION_TO_STATUS = {
|
||||||
eyes: "Done",
|
eyes: "Done",
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ describe("project-graphql-updater", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("getProjectFields", () => {
|
describe("getProjectFields", () => {
|
||||||
it("should fetch project fields successfully", async () => {
|
it("should fetch project fields for user successfully", async () => {
|
||||||
const mockProject = {
|
const mockProject = {
|
||||||
id: "project-123",
|
id: "project-123",
|
||||||
fields: {
|
fields: {
|
||||||
@@ -133,7 +133,35 @@ describe("project-graphql-updater", () => {
|
|||||||
|
|
||||||
const { getProjectFields } = await import("../bot/handlers/project-graphql-updater.js");
|
const { getProjectFields } = await import("../bot/handlers/project-graphql-updater.js");
|
||||||
|
|
||||||
const result = await getProjectFields("BlackRoad-OS", 1);
|
const result = await getProjectFields("BlackRoad-OS", 1, false);
|
||||||
|
|
||||||
|
expect(result).toEqual(mockProject);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should fetch project fields for organization successfully", async () => {
|
||||||
|
const mockProject = {
|
||||||
|
id: "org-project-123",
|
||||||
|
fields: {
|
||||||
|
nodes: [
|
||||||
|
{ id: "field-1", name: "Status", options: [{ id: "opt-1", name: "Done" }] },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
mockFetch.mockResolvedValueOnce({
|
||||||
|
ok: true,
|
||||||
|
json: async () => ({
|
||||||
|
data: {
|
||||||
|
organization: {
|
||||||
|
projectV2: mockProject,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
const { getProjectFields } = await import("../bot/handlers/project-graphql-updater.js");
|
||||||
|
|
||||||
|
const result = await getProjectFields("BlackRoad-OS", 1, true);
|
||||||
|
|
||||||
expect(result).toEqual(mockProject);
|
expect(result).toEqual(mockProject);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user