Skip to content

Commit ca2eedd

Browse files
Write collected user activity history to users' Skills Issue, pt 3 (#8260)
* add funct to minimize bot comments * Update label-directory.json normalizing new `skillsIssueCompleted` label * Update first-post-to-skills-issue.js change postComment() parameters to match existing * Update add-label.js added MARKER exclusion * Update add-label.js added to note excluding Skills Issue Activity comment * split csv for testing, add new cron
1 parent 696c7a3 commit ca2eedd

File tree

7 files changed

+695
-621
lines changed

7 files changed

+695
-621
lines changed

.github/workflows/activity-history-post.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Post Activity History to all Users
22

33
on:
44
schedule:
5-
- cron: 45 22 9 8 *
5+
- cron: 25 4 10 8 *
66
workflow_dispatch:
77

88
jobs:

github-actions/activity-trigger/first-post-to-skills-issue.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const postComment = require('../utils/post-issue-comment');
66
const checkTeamMembership = require('../utils/check-team-membership');
77
const statusFieldIds = require('../utils/_data/status-field-ids');
88
const mutateIssueStatus = require('../utils/mutate-issue-status');
9+
const minimizeIssueComment = require('../utils/hide-issue-comment');
10+
const getIssueComments = require('./get-issue-comments');
911

1012
// Global variables
1113
var github;
@@ -28,7 +30,7 @@ async function firstPostToSkillsIssue({g, c}) {
2830

2931

3032
try {
31-
const csvPath = 'github-actions/activity-trigger/member_activity_history_bot.csv';
33+
const csvPath = 'github-actions/activity-trigger/member_activity_history_bot_1.csv';
3234
const csvContent = fs.readFileSync(csvPath, 'utf-8');
3335

3436
// Parse CSV assuming
@@ -49,8 +51,14 @@ async function firstPostToSkillsIssue({g, c}) {
4951

5052
// Since we know this is the first run and no matching issue comments exist yet, we can post immediately
5153
const body = `${MARKER}\n## Activity Log: ${username}\n\n##### ⚠ Important note: The bot updates this issue automatically - do not edit\n\n${message}`;
52-
await postComment(github, context, skillsIssueNum, body);
54+
await postComment(skillsIssueNum, body, github, context);
5355

56+
// Perform cleanup of comments
57+
const commentIds = await getIssueComments(github, context, skillsIssueNum);
58+
for (const commentId of commentIds) {
59+
await minimizeIssueComment(github, commentId);
60+
}
61+
5462
// Check whether eventActor is team member; if so open issue and move to "In progress"
5563
const isActiveMember = await checkTeamMembership(github, username, team);
5664

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
const tenDaysAgo = new Date();
2+
tenDaysAgo.setDate(tenDaysAgo.getDate() - 10);
3+
4+
5+
async function getIssueComments(github, context, issueNum) {
6+
7+
const owner = context.repo.owner;
8+
const repo = context.repo.repo;
9+
10+
11+
const query = `query($owner: String!, $repo: String!, $issueNum: Int!) {
12+
repository(owner: $owner, name: $repo) {
13+
issue(number: $issueNum) {
14+
comments(first: 100) {
15+
nodes {
16+
id
17+
author { login }
18+
createdAt
19+
isMinimized
20+
minimizedReason
21+
}
22+
}
23+
}
24+
}
25+
}`;
26+
27+
const variables = {
28+
owner: owner,
29+
repo: repo,
30+
issueNum: issueNum,
31+
};
32+
33+
34+
let commentIds = [];
35+
let botNames = ["github-actions[bot]", "HackforLABot"];
36+
37+
try {
38+
const response = await github.graphql(query, variables);
39+
40+
let comments = response.repository.issue.comments.nodes || [];
41+
42+
for (let comment of comments) {
43+
let created = new Date(comment.createdAt);
44+
45+
if (
46+
botNames.includes(comment.author?.login) &&
47+
created < tenDaysAgo &&
48+
!comment.isMinimized
49+
) {
50+
commentIds.push(comment.id);
51+
}
52+
}
53+
} catch (error) {
54+
throw new Error(`Error retrieving comments for issue #${issueNum}: ${error}`);
55+
}
56+
57+
return commentIds;
58+
}
59+

github-actions/activity-trigger/member_activity_history_bot_1.csv

Lines changed: 617 additions & 0 deletions
Large diffs are not rendered by default.

github-actions/activity-trigger/member_activity_history_bot.csv renamed to github-actions/activity-trigger/member_activity_history_bot_2.csv

Lines changed: 0 additions & 616 deletions
Large diffs are not rendered by default.

github-actions/trigger-schedule/add-update-label-weekly/add-label.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,12 @@ function formatComment(assignees, labelString) {
369369
function isCommentByBot(data) {
370370
let botLogin = "github-actions[bot]";
371371
let hflaBotLogin = "HackforLABot";
372+
// If the comment includes the MARKER, return false
373+
let MARKER = '<!-- Skills Issue Activity Record -->';
374+
if (data.body.includes(MARKER)) {
375+
console.log(`Found "Skills Issue Activity Record" - do not minimize`);
376+
return false;
377+
}
372378
return data.actor.login === botLogin || data.actor.login === hflaBotLogin;
373379
}
374380

github-actions/utils/_data/label-directory.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -855,8 +855,8 @@
855855
"Skill: enhance",
856856
8273641077
857857
],
858-
"NEW-skillsIssueCompleted": [
858+
"skillsIssueCompleted": [
859859
"Skills Issue Completed",
860860
9085307637
861861
]
862-
}
862+
}

0 commit comments

Comments
 (0)