Skip to content

Improve GitHub Actions workflows: add permissions, consolidate build steps, and configure artifact retention #102

Improve GitHub Actions workflows: add permissions, consolidate build steps, and configure artifact retention

Improve GitHub Actions workflows: add permissions, consolidate build steps, and configure artifact retention #102

Workflow file for this run

name: 🤖 Auto Reply to Issues & PRs
on:
issues:
types: [opened, reopened]
pull_request_target:
types: [opened, reopened, synchronize]
permissions:
issues: write
pull-requests: write
jobs:
auto-comment:
runs-on: ubuntu-latest
steps:
- name: 🧠 Auto Comment
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const repo = context.repo;
async function commentExists(issue_number, messageSnippet) {
const comments = await github.rest.issues.listComments({
owner: repo.owner,
repo: repo.repo,
issue_number
});
return comments.data.some(c => c.body.includes(messageSnippet));
}
async function addReaction(issue_number, reaction) {
const reactions = await github.rest.reactions.listForIssue({
owner: repo.owner,
repo: repo.repo,
issue_number
});
if (!reactions.data.some(r => r.content === reaction)) {
await github.rest.reactions.createForIssue({
owner: repo.owner,
repo: repo.repo,
issue_number,
content: reaction
});
}
}
async function addLabels(issue_number, labels) {
try {
await github.rest.issues.addLabels({
owner: repo.owner,
repo: repo.repo,
issue_number,
labels
});
} catch (err) {
core?.info?.("Could not add labels: " + err.message);
}
}
// Handle Pull Requests
if (context.payload.pull_request) {
const pr = context.payload.pull_request;
const user = pr.user?.login || 'contributor';
const prNumber = pr.number;
const message = `🚀 Hi @${user}!
Thank you for contributing to **MyCMD**. A maintainer will review your PR shortly. 🎉

Check failure on line 70 in .github/workflows/auto-reply.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/auto-reply.yml

Invalid workflow file

You have an error in your yaml syntax on line 70
### Thank you for raising this issue!
We'll review it as soon as possible. We truly appreciate your contributions! ✨ Meanwhile make sure you've visited the README.md, CONTRIBUTING.md, and CODE_OF_CONDUCT.md before creating a PR for this. Also, please do NOT create a PR until this issue has been assigned to you. 😊`;
const gif = "![TrustTheProcess](https://media0.giphy.com/media/v1.Y2lkPTc5MGI3NjExbWtoOWpsMnozdXd0MmJxejhiNGwwdjltY3dyNW80NHg2Ym01YTdlMSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/mPKa6OI5oRsmextwBq/giphy.gif)";
if (!(await commentExists(prNumber, "Thank you for contributing to **MyCMD**"))) {
await github.rest.issues.createComment({
owner: repo.owner,
repo: repo.repo,
issue_number: prNumber,
body: message + "\n\n" + gif
});
}
await addReaction(prNumber, "rocket");
const headRepoFull = pr.head?.repo?.full_name || '';
const baseFull = `${repo.owner}/${repo.repo}`;
const isFork = headRepoFull.toLowerCase() !== baseFull.toLowerCase();
const labels = ["needs-review"];
if (isFork) labels.push("from-fork");
await addLabels(prNumber, labels);
return;
}
// Handle Issues
if (context.payload.issue) {
const issue = context.payload.issue;
const user = issue.user?.login || 'contributor';
const issueNumber = issue.number;
const message = `👋 Hi @${user}!
Thanks for opening an issue in **MyCMD**. We’ll review it soon — please ensure reproduction steps and logs are included.`;
if (!(await commentExists(issueNumber, "Thanks for opening an issue in **MyCMD**"))) {
await github.rest.issues.createComment({
owner: repo.owner,
repo: repo.repo,
issue_number: issueNumber,
body: message
});
}
await addReaction(issueNumber, "tada");
await addLabels(issueNumber, ["triage", "needs-info"]);
return;
}
core?.info?.('No issue or pull_request payload found. Nothing to do.');