-
Notifications
You must be signed in to change notification settings - Fork 774
added non-core-qn workflow #8889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
8aa2377
added non-core-qn workflow
tellmeY18 955d72d
replaced bash with js
tellmeY18 67d5058
made it to single step
tellmeY18 bbd42dd
Merge branch 'develop' into workflow
tellmeY18 3cee707
Merge branch 'ohcnetwork:develop' into workflow
tellmeY18 f3b6c58
updated to use env
tellmeY18 1e41a8b
setup variables as secrets
tellmeY18 176acdd
Merge branch 'develop' into workflow
tellmeY18 3b1917d
Merge branch 'develop' into workflow
tellmeY18 0b5bfea
Merge branch 'develop' into workflow
tellmeY18 ec2c484
applied coderabbitai suggested changes
tellmeY18 cfc8b12
Merge branch 'develop' into workflow
tellmeY18 1715084
Merge branch 'develop' into workflow
tellmeY18 968e597
Merge branch 'ohcnetwork:develop' into workflow
tellmeY18 cc9592d
Improved Slack message.
tellmeY18 09d6bbd
updated the script to use vars instead of secrets
tellmeY18 70945b4
use slack workflow instead of slCK APPS
tellmeY18 9a49d8e
Merge branch 'develop' into workflow
tellmeY18 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,87 @@ | ||
name: Notify Core Team on Non-Core Questions | ||
on: | ||
issue_comment: | ||
types: [created] | ||
permissions: | ||
issues: write | ||
pull-requests: write | ||
jobs: | ||
notify_core_team: | ||
runs-on: ubuntu-latest | ||
env: | ||
ALLOWED_USERNAMES: ${{ vars.ALLOWED_USERNAMES }} | ||
QUESTION_KEYWORDS: ${{ vars.QUESTION_KEYWORDS }} | ||
QUESTION_LABELS: ${{ vars.QUESTION_LABELS }} | ||
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} | ||
steps: | ||
- name: Check and Notify | ||
uses: actions/github-script@v6 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
console.log('Script started'); | ||
const isOrgMember = (commenter, allowedUsers) => { | ||
return allowedUsers.split(',').map(u => u.trim()).includes(commenter); | ||
}; | ||
const containsQuestionKeywords = (text, keywords) => { | ||
return keywords.split(',').map(k => k.trim()).some(keyword => | ||
text.toLowerCase().includes(keyword.toLowerCase()) | ||
); | ||
}; | ||
const addLabelsToIssue = async (github, context, labelsString) => { | ||
const labels = labelsString.split(',').map(label => label.trim()).filter(label => label); | ||
if (labels.length > 0) { | ||
console.log('Adding labels:', labels); | ||
await github.rest.issues.addLabels({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: context.payload.issue.number, | ||
labels: labels | ||
}); | ||
} | ||
}; | ||
const sendSlackNotification = async (webhook, payload) => { | ||
const response = await fetch(webhook, { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: JSON.stringify(payload) | ||
}); | ||
if (!response.ok) { | ||
throw new Error(`HTTP error! status: ${response.status}`); | ||
} | ||
}; | ||
const commenter = context.payload.comment.user.login; | ||
console.log('Commenter:', commenter); | ||
if (!isOrgMember(commenter, process.env.ALLOWED_USERNAMES)) { | ||
const commentBody = context.payload.comment.body; | ||
const sanitizedComment = commentBody | ||
?.replace(/[^\w\s?]/gi, '') | ||
.toLowerCase(); | ||
console.log('Comment body:', sanitizedComment); | ||
if (containsQuestionKeywords(sanitizedComment, process.env.QUESTION_KEYWORDS)) { | ||
try { | ||
console.log('Adding labels to the issue'); | ||
await addLabelsToIssue(github, context, process.env.QUESTION_LABELS); | ||
console.log('Labels added successfully'); | ||
const issueUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/issues/${context.payload.issue.number}`; | ||
const issueTitle = context.payload.issue.title; | ||
const issueNumber = context.payload.issue.number; | ||
console.log('Issue URL:', issueUrl); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we should keep these logs |
||
console.log('Issue Title:', issueTitle); | ||
console.log('Issue Number:', issueNumber); | ||
const payload = { | ||
link: issueUrl, | ||
Question: commentBody, | ||
"issue-number": issueNumber, | ||
title: issueTitle, | ||
user: commenter | ||
}; | ||
await sendSlackNotification(process.env.SLACK_WEBHOOK, payload); | ||
console.log('Slack notification sent successfully'); | ||
} catch (error) { | ||
console.error('Workflow failed:', error.message); | ||
core.setFailed(`Workflow failed: ${error.message}`); | ||
} | ||
} | ||
} | ||
console.log('Script ended'); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The steps should be skipped if the variables/ secrets are not available