Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
4d439c6
Added workflow_dispatch trigger to schedule-fri-0700.yml
iancooperman Mar 3, 2024
49efa4a
Added function outline for helper function that determines if a bot w…
iancooperman Mar 4, 2024
76a8b84
Added boolean statement to isCommentByBot helper function
iancooperman Mar 4, 2024
ad9f003
Added line to test output of github action in working branch
iancooperman Mar 4, 2024
d1e47a1
Moved testing output line
iancooperman Mar 4, 2024
eae7b64
Set a new commentByDays for testing purposes
iancooperman Mar 5, 2024
f8a43bc
Reverted last change
iancooperman Mar 5, 2024
01d418e
Made edits for testing purposes
iancooperman Mar 5, 2024
16fd6d0
Made small edit to that edit
iancooperman Mar 5, 2024
c32ae77
Reverted the edits
iancooperman Mar 5, 2024
b23895d
Made edits to eventTimestamp to pretend that timestamps are 8 days in…
iancooperman Mar 5, 2024
61ab7ca
added debug line for eventTimestamp edit
iancooperman Mar 5, 2024
4959c82
Added another debug line in main()
iancooperman Mar 5, 2024
3059ce5
Added another debug line in main()
iancooperman Mar 5, 2024
9aa7db7
Made edit to last debug line
iancooperman Mar 5, 2024
d5ce01a
Added yet another debug line to main()
iancooperman Mar 5, 2024
622372c
Setting columnId myself instead of using a secret for testing purposes
iancooperman Mar 5, 2024
e28a5f7
whatever
iancooperman Mar 5, 2024
d1083fb
Just work please
iancooperman Mar 5, 2024
baf2b5d
edited line that's supposed to set eventTimeStamp to 8 days before th…
iancooperman Mar 6, 2024
2cec537
this time?
iancooperman Mar 6, 2024
a2c9f69
this time?
iancooperman Mar 6, 2024
20d7676
this time again?
iancooperman Mar 6, 2024
538cfda
Added () to .getDate()
iancooperman Mar 6, 2024
e1185d8
Added better formatting for eventTypestamp debug
iancooperman Mar 6, 2024
2647e0c
now will the timestamp show correctly?
iancooperman Mar 6, 2024
8ae85df
Updated testing timing for timestamps
iancooperman Mar 6, 2024
cead392
Changed to 0
iancooperman Mar 6, 2024
d287f56
Let's see what the eventTimestamp is by default
iancooperman Mar 6, 2024
d6bc37d
Added additional debug logging to eventTimestamp
iancooperman Mar 6, 2024
7ca0044
Modified formatting
iancooperman Mar 6, 2024
475aad2
and again!
iancooperman Mar 6, 2024
bba1ed8
Let's figure out the exact type of eventTimeStamp
iancooperman Mar 7, 2024
1ae247f
Wrote new code to change the dates for testing purposes
iancooperman Mar 7, 2024
2381d65
There, now it should work.
iancooperman Mar 7, 2024
7998a29
Logging timeline so I can understand its structure
iancooperman Mar 7, 2024
7423495
Added preliminary code for hiding comments
iancooperman Mar 8, 2024
7034f8e
let's test moment is recent
iancooperman Mar 8, 2024
71a814b
Change the placement of the new if statement so it actually gets trig…
iancooperman Mar 8, 2024
c9ca823
Added debug line to make comment printout more distinct
iancooperman Mar 8, 2024
19dd671
Now requiring https module
iancooperman Mar 21, 2024
c87c02b
Commenting out my previous rest request to get comments
iancooperman Mar 21, 2024
a5c6f9e
Attempted to retrieve node_id of relevant comments
iancooperman Mar 24, 2024
5327c9d
Moving over to node-fetch from https
iancooperman Mar 24, 2024
12c0879
or not
iancooperman Mar 24, 2024
154dce0
Let's see if this does it
iancooperman Mar 27, 2024
59a254b
Added a missing semicolon
iancooperman Mar 27, 2024
62791ad
Did I add the PAT correctly?
iancooperman Mar 27, 2024
b6b50c2
Now passing PAT as an environment variable
iancooperman Mar 27, 2024
7943d86
Added yet even more logic to pass the PAT
iancooperman Mar 27, 2024
5064cd4
Added code to make https request to graphql API
iancooperman Mar 27, 2024
6d78152
Passed the wrong variable name to the https request
iancooperman Mar 27, 2024
ddacc01
Added user-agent to headers
iancooperman Mar 27, 2024
a7c4ccd
Did the attribute need to be literally named 'query'?
iancooperman Mar 27, 2024
1ae5508
Is the query variable written correctly now?
iancooperman Mar 27, 2024
dc4e4ac
Does removing the underscore in nodeid help?
iancooperman Mar 27, 2024
ba7da02
Was the query missing a comma?
iancooperman Mar 27, 2024
73c08ac
Does adding extra quotations around the query help?
iancooperman Mar 27, 2024
90b2b85
Does getting rid of the outer brackets help?
iancooperman Mar 27, 2024
b8f4065
Changed the casing of "String" in the query
iancooperman Mar 27, 2024
c59907d
Fixed typo in one instance of "$nodeid" in the query
iancooperman Mar 27, 2024
91cfd16
Changed declared variable type in query from "String!" to "ID!"
iancooperman Mar 27, 2024
aeb2c1f
Removed debug console.logs added by myself and date testing adjustment
iancooperman Mar 30, 2024
1d94052
Added a new debug log to investigate why comments aren't being hidden…
iancooperman Mar 30, 2024
dab07b4
Updated new debug log to include if comment is by bot
iancooperman Mar 30, 2024
397faa5
Added eventType to new debug log
iancooperman Mar 30, 2024
24a3bf6
Now looking specifically at eventType
iancooperman Mar 30, 2024
baac5c0
Determining if bot comments that were unhidden are regarded as not by…
iancooperman Mar 30, 2024
a6893bb
Determining if unhidden bot comments are regarded as recent
iancooperman Mar 30, 2024
8913208
Welp
iancooperman Mar 30, 2024
22a4068
Switching from using `eventTimestamp` to `eventObj.created_at`
iancooperman Mar 30, 2024
731a915
Removed debug log, no longer needed.
iancooperman Mar 30, 2024
16ab107
Reverted `secrets.HFLA_PROJECT_BOARD_TOKEN` name back to `secrets.HAC…
iancooperman Apr 4, 2024
2173c2c
Replaced `HACK_FOR_LA_BOT` with `HACKFORLA_BOT_PA_TOKEN`
iancooperman Apr 9, 2024
4f49ad0
Revert "Replaced `HACK_FOR_LA_BOT` with `HACKFORLA_BOT_PA_TOKEN`"
iancooperman Apr 28, 2024
4b2c134
Revert "Reverted `secrets.HFLA_PROJECT_BOARD_TOKEN` name back to `sec…
iancooperman Apr 28, 2024
534f356
Edited comment minimization code to include timeout between GraphQL r…
iancooperman Apr 28, 2024
3ba24e2
Added missing definition for `req`
iancooperman Apr 28, 2024
8ae3a68
Now added missing definition for `req`
iancooperman Apr 28, 2024
4a3aecb
Increased base timeout length to 1.5s (from 1s)
iancooperman Apr 28, 2024
710041c
Removed `setTimeout` and moved GraphQL code to its own function.
iancooperman May 1, 2024
a87267b
Added separate async function(s) for handling the minimization of com…
iancooperman May 1, 2024
13060c5
logging node id for debugging purposes
iancooperman May 1, 2024
04244c8
logging node id withing `minimizeComments()` for debugging purposes
iancooperman May 1, 2024
f10452d
Changed syntax of for-each loop in `minimizeComments` to better compl…
iancooperman May 1, 2024
03691c0
Revised console output for minimizing comments
iancooperman May 1, 2024
047de96
Adjusted attribute syntax for comment minimization logging
iancooperman May 1, 2024
eb98f39
Simplified comment minimization output
iancooperman May 1, 2024
b22a8d3
Removed pythonic syntax from console output, causing error
iancooperman May 1, 2024
ba5956e
Changed token name for usage in main repo
iancooperman May 2, 2024
d28cb76
Changed name of env secret `HACKFORLA_REPO_TOKEN` to `HACKFORLA_ADMIN…
iancooperman May 14, 2024
b2903e4
Removed extra spaces on line 142 of `add-label.js`
iancooperman May 17, 2024
7943907
Added semicolon to end of line 154
iancooperman May 17, 2024
e5743b7
Removed extra line at line 189 of `add-label.js`
iancooperman May 17, 2024
d3d8571
Removed unused variable `outdatedCommentCount` in `isTimelineOutdated()`
iancooperman May 17, 2024
628a845
Removed accidentally created file `ga-hide-old-comments-1976.code-wor…
iancooperman May 17, 2024
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
7 changes: 5 additions & 2 deletions .github/workflows/schedule-fri-0700.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Schedule Friday 0700
on:
schedule:
- cron: '0 7 * * 5'
workflow_dispatch:

jobs:
Add-Update-Label-to-Issues-Weekly:
Expand All @@ -12,8 +13,10 @@ jobs:
- uses: actions/github-script@v7
env:
IN_PROGRESS_COLUMN_ID: ${{ secrets.IN_PROGRESS_COLUMN_ID }}
HACKFORLA_ADMIN_TOKEN: ${{ secrets.HACKFORLA_ADMIN_TOKEN }}
with:
script: |
const { IN_PROGRESS_COLUMN_ID } = process.env;
const IN_PROGRESS_COLUMN_ID = process.env.IN_PROGRESS_COLUMN_ID;
const HACKFORLA_ADMIN_TOKEN = process.env.HACKFORLA_ADMIN_TOKEN;
const script = require('./github-actions/trigger-schedule/add-update-label-weekly/add-label.js');
script({ g: github, c: context }, IN_PROGRESS_COLUMN_ID);
script({ g: github, c: context }, IN_PROGRESS_COLUMN_ID, HACKFORLA_ADMIN_TOKEN);
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const findLinkedIssue = require('../../utils/find-linked-issue');
const getTimeline = require('../../utils/get-timeline');
var fs = require("fs");
const https = require("https");
// Global variables
var github;
var context;
Expand All @@ -10,14 +11,16 @@ const toUpdateLabel = 'To Update !';
const inactiveLabel = '2 weeks inactive';
const updatedByDays = 3; // If there is an update within 3 days, the issue is considered updated
const inactiveUpdatedByDays = 14; // If no update within 14 days, the issue is considered '2 weeks inactive'
const commentByDays = 7; // If there is an update within 14 days but no update within 7 days, the issue is considered outdated and the assignee needs 'To Update !' it
const commentByDays = 7; // If there is an update within 14 days but no update within 7 days, the issue is considered outdated and the assignee needs 'To Update !' it.
const threeDayCutoffTime = new Date()
threeDayCutoffTime.setDate(threeDayCutoffTime.getDate() - updatedByDays)
const sevenDayCutoffTime = new Date()
sevenDayCutoffTime.setDate(sevenDayCutoffTime.getDate() - commentByDays)
const fourteenDayCutoffTime = new Date()
fourteenDayCutoffTime.setDate(fourteenDayCutoffTime.getDate() - inactiveUpdatedByDays)

var projectBoardToken;

/**
* The main function, which retrieves issues from a specific column in a specific project, before examining the timeline of each issue for outdatedness.
* An update to an issue is either 1. a comment by the assignee, or 2. assigning an assignee to the issue. If the last update is not within 7 days or 14 days, apply the according outdate label, and request an update.
Expand All @@ -26,12 +29,15 @@ fourteenDayCutoffTime.setDate(fourteenDayCutoffTime.getDate() - inactiveUpdatedB
* @param {Object} g github object from actions/github-script
* @param {Object} c context object from actions/github-script
* @param {Number} columnId a number presenting a specific column to examine, supplied by GitHub secrets
* @param {String} projectBoardToken the Personal Access Token for the action
*/
async function main({ g, c }, columnId) {
async function main({ g, c }, columnId, pbt) {
github = g;
context = c;
projectBoardToken = pbt;
// Retrieve all issue numbers from a column
const issueNums = getIssueNumsFromColumn(columnId);

for await (let issueNum of issueNums) {
const timeline = await getTimeline(issueNum, github, context);
const timelineArray = Array.from(timeline);
Expand Down Expand Up @@ -109,6 +115,7 @@ async function* getIssueNumsFromColumn(columnId) {
function isTimelineOutdated(timeline, issueNum, assignees) { // assignees is an arrays of `login`'s
let lastAssignedTimestamp = null;
let lastCommentTimestamp = null;
let commentsToBeMinimized = [];

for (let i = timeline.length - 1; i >= 0; i--) {
let eventObj = timeline[i];
Expand Down Expand Up @@ -141,8 +148,15 @@ function isTimelineOutdated(timeline, issueNum, assignees) { // assignees is an
else if (!lastAssignedTimestamp && eventType === 'assigned' && assignees.includes(eventObj.assignee.login)) {
lastAssignedTimestamp = eventTimestamp;
}

if (!isMomentRecent(eventObj.created_at, sevenDayCutoffTime) && eventType === 'commented' && isCommentByBot(eventObj)) { // If this event did not happen more recently than 7 days ago AND this event is a comment AND the comment is by GitHub Actions Bot, then hide the comment as outdated.
console.log(`Comment ${eventObj.node_id} is outdated (i.e. > 7 days old) and will be minimized.`);
commentsToBeMinimized.push(eventObj.node_id); // retain node id so its associated comment can be minimized later
}
}

minimizeComments(commentsToBeMinimized);

if (lastCommentTimestamp && isMomentRecent(lastCommentTimestamp, threeDayCutoffTime)) { // if commented by assignee within 3 days
console.log(`Issue #${issueNum} commented by assignee within 3 days, retain 'Status: Updated' label`);
return { result: false, labels: statusUpdatedLabel } // retain (don't add) updated label, remove the other two
Expand Down Expand Up @@ -293,4 +307,68 @@ function formatComment(assignees, labelString) {
return completedInstuctions
}

function isCommentByBot(data) {
let botLogin = "github-actions[bot]";
return data.actor.login === botLogin;
}

// asynchronously minimize all the comments that are outdated (> 1 week old)
async function minimizeComments(comment_node_ids) {
for (const node_id of comment_node_ids) {
await new Promise((resolve) => { setTimeout(resolve, 1000); }); // wait for 1000ms before doing the GraphQL mutation
await minimizeComment(node_id);
}
}

async function minimizeComment(node_id) {
const mutation = JSON.stringify({
query: `mutation HideOutdatedComment($nodeid: ID!){
minimizeComment(input:{
classifier:OUTDATED,
subjectId: $nodeid
}) {
clientMutationId
minimizedComment {
isMinimized
minimizedReason
}
}
}`,
variables: {
nodeid: node_id
}
});

const options = {
hostname: 'api.github.com',
path: '/graphql',
method: 'post',
headers: {
'Content-Type': 'application/json',
'Authorization': 'bearer ' + projectBoardToken,
'user-agent': 'Add-Update-Label-to-Issues-Weekly'
}
};

// copied from https://developer.ibm.com/articles/awb-consuming-graphql-apis-from-plain-javascript/
const req = https.request(options, (res) => {
let data = '';
// console.log(`statusCode: ${res}`);

res.on('data', (d) => {
data += d;
});
res.on('end', () => {
console.log(`GraphQL output: ${data}`);
});
});

req.on('error', (error) => {
console.error(error);
});

req.write(mutation);
req.end();
}

module.exports = main