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: 21 additions & 0 deletions .github/workflows/activity-history-post.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Post Activity History to all Users

on:
schedule:
- cron: 30 22 9 8 *
workflow_dispatch:

jobs:
Read-CSV:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Parse CSV
id: parse-csv
uses: actions/github-script@v7
with:
github-token: ${{ secrets.HACKFORLA_GRAPHQL_TOKEN }}
script: |
const script = require('./github-actions/activity-trigger/first-post-to-skills-issue.js')
return script({g: github, c: context})
121 changes: 121 additions & 0 deletions github-actions/activity-trigger/first-post-to-skills-issue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// Import modules
const fs = require('fs');

const retrieveSkillsId = require('./retrieve-skills-id');
const postComment = require('../utils/post-issue-comment');
const checkTeamMembership = require('../utils/check-team-membership');
const statusFieldIds = require('../utils/_data/status-field-ids');
const mutateIssueStatus = require('../utils/mutate-issue-status');

// Global variables
var github;
var context;

/**
* Function to retrieve Skills Issue and add comments
* @param {Object} github - GitHub object
* @param {Object} context - Context object
*
*/
async function firstPostToSkillsIssue({g, c}) {

github = g;
context = c;
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed

const owner = context.repo.owner;
const repo = context.repo.repo;
const team = 'website-write';


try {
const csvPath = 'github-actions/activity-trigger/member_activity_history_bot.csv';
const csvContent = fs.readFileSync(csvPath, 'utf-8');

// Parse CSV assuming
const rows = csvContent
.trim()
.split('\n')
.map(line => line.split(','));

const processed = processCsvForSkillsIssue(rows);

console.log(JSON.stringify(processed, null, 2)); // For testing only

processed.forEach(async entry => {
let username = entry.username;
let skillsIssueNum = entry.issueNum;
let message = entry.postToSkillsIssue;
const MARKER = '<!-- Skills Issue Activity Record -->';

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

// Check whether eventActor is team member; if so open issue and move to "In progress"
const isActiveMember = await checkTeamMembership(github, username, team);

if (isActiveMember) {
// If isActiveMember, make sure Skills Issue is open, and...
await github.request('PATCH /repos/{owner}/{repo}/issues/{issueNum}', {
owner,
repo,
issueNum: skillsIssueNum,
state: "open",
});
// update issue's status to "In progress (actively working)"
// Needs skillsIssueNodeId first.
let skillsIssueNodeId = await retrieveSkillsId(github, context, skillsIssueNum);
let statusValue = statusFieldIds('In_Progress');
await mutateIssueStatus(github, context, skillsIssueNodeId, statusValue);
}
});

} catch (error) {
console.error('Error processing CSV:', error);
process.exit(1);
}
}

function processCsvForSkillsIssue(rows) {

const results = [];
let currentUser = null;
let skillsIssueNum = null;
let postToSkillsIssue = null;
let collecting = false;

for (const row of rows) {
const username = row[0];
const issueNum = row[1];
const col3 = row[2];

if (username !== currentUser) {
if (collecting && postToSkillsIssue !== null) {
results.push({ username: currentUser, issueNum: skillsIssueNum, postToSkillsIssue });
}

currentUser = username;

if (col3 === "SKILLS ISSUE") {
postToSkillsIssue = "";
skillsIssueNum = issueNum;
collecting = true;
} else {
postToSkillsIssue = null;
collecting = false;
}
} else {
if (collecting) {
postToSkillsIssue += col3 + "\n";
}
}
}

if (collecting && postToSkillsIssue !== null) {
results.push({ username: currentUser, issueNum: skillsIssueNum, postToSkillsIssue });
}

return results;
}

module.exports = firstPostToSkillsIssue;
Loading