-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from gittogethers/AndreaGriffiths11/add-extrac…
…t-usernames Add script to extract usernames from issues and comments
- Loading branch information
Showing
3 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: Extract Usernames | ||
|
||
on: | ||
issues: | ||
types: [opened, edited] | ||
issue_comment: | ||
types: [created, edited] | ||
|
||
jobs: | ||
extract_usernames: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: '14' | ||
|
||
- name: Run extract_usernames script | ||
run: node scripts/extract_usernames.js ${{ github.event.issue.number }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "nerdearla-argentina", | ||
"version": "1.0.0", | ||
"description": "A repository for Nerdearla Argentina event", | ||
"main": "index.js", | ||
"scripts": { | ||
"extract_usernames": "node scripts/extract_usernames.js" | ||
}, | ||
"dependencies": { | ||
"@octokit/rest": "^18.0.0", | ||
"fs": "0.0.1-security" | ||
}, | ||
"author": "", | ||
"license": "ISC" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const fs = require('fs'); | ||
const { Octokit } = require('@octokit/rest'); | ||
|
||
const octokit = new Octokit({ | ||
auth: process.env.GITHUB_TOKEN, | ||
}); | ||
|
||
async function extractUsernames(issueNumber) { | ||
try { | ||
const { data: issue } = await octokit.issues.get({ | ||
owner: 'gittogethers', | ||
repo: 'nerdearla-argentina', | ||
issue_number: issueNumber, | ||
}); | ||
|
||
const usernames = new Set(); | ||
|
||
// Extract usernames from issue body | ||
const bodyUsernames = issue.body.match(/@[a-zA-Z0-9_-]+/g); | ||
if (bodyUsernames) { | ||
bodyUsernames.forEach((username) => usernames.add(username)); | ||
} | ||
|
||
// Extract usernames from comments | ||
const { data: comments } = await octokit.issues.listComments({ | ||
owner: 'gittogethers', | ||
repo: 'nerdearla-argentina', | ||
issue_number: issueNumber, | ||
}); | ||
|
||
comments.forEach((comment) => { | ||
const commentUsernames = comment.body.match(/@[a-zA-Z0-9_-]+/g); | ||
if (commentUsernames) { | ||
commentUsernames.forEach((username) => usernames.add(username)); | ||
} | ||
}); | ||
|
||
// Print usernames to console | ||
console.log('Extracted Usernames:', Array.from(usernames)); | ||
|
||
// Save usernames to file | ||
fs.writeFileSync('usernames.txt', Array.from(usernames).join('\n')); | ||
} catch (error) { | ||
console.error('Error extracting usernames:', error); | ||
} | ||
} | ||
|
||
const issueNumber = process.argv[2]; | ||
if (!issueNumber) { | ||
console.error('Please provide an issue number as a command-line argument.'); | ||
process.exit(1); | ||
} | ||
|
||
extractUsernames(issueNumber); |