Offline gym log for Android. No account, no ads, no internet.
Dart androidbodybuildingdartexercisesf-droidfitnessfluttergymgym-apphealthprivacyself-hostedworkoutworkout-appworkout-tracker
ci: welcome new issues and add /claim
InlitXc5b182c5e372
diff --git a/.github/workflows/claim.yml b/.github/workflows/claim.ymlnew file mode 100644index 0000000..449dfc6--- /dev/null+++ b/.github/workflows/claim.yml@@ -0,0 +1,107 @@+# /claim and /unclaim for issues.+#+# - `/claim` on an issue labelled `approved` assigns the commenter.+# - `/claim` on an issue that is not approved yet labels it `claim-pending`;+# when the owner adds `approved`, the first person who claimed it is assigned.+# - `/unclaim` removes the commenter from the issue.+#+# Only the event payload and the API are read; no code from the repo is run.++name: Claim++on:+ issue_comment:+ types: [created]+ issues:+ types: [labeled]++permissions:+ issues: write++concurrency:+ group: claim-${{ github.event.issue.number }}+ cancel-in-progress: false++jobs:+ claim:+ if: >-+ (github.event_name == 'issue_comment' &&+ github.event.issue.pull_request == null &&+ github.event.comment.user.type == 'User') ||+ (github.event_name == 'issues' && github.event.label.name == 'approved')+ runs-on: ubuntu-latest+ steps:+ - uses: actions/github-script@v9+ with:+ script: |+ const { owner, repo } = context.repo;+ const issue = context.payload.issue;+ const number = issue.number;+ const APPROVED = 'approved';+ const PENDING = 'claim-pending';++ const labels = () => issue.labels.map(l => l.name);+ const reply = body =>+ github.rest.issues.createComment({ owner, repo, issue_number: number, body });+ const isCommand = (text, cmd) => text.trim().toLowerCase() === cmd;+ const assignees = issue.assignees.map(a => a.login);++ async function removePending() {+ if (!labels().includes(PENDING)) return;+ await github.rest.issues.removeLabel({ owner, repo, issue_number: number, name: PENDING })+ .catch(() => {});+ }++ async function assign(login) {+ await github.rest.issues.addAssignees({ owner, repo, issue_number: number, assignees: [login] });+ await removePending();+ await reply(`@${login}, this issue is now yours. Thanks for helping! When you open the pull request, link it with \`Fixes #${number}\`. If you can't finish it, comment \`/unclaim\` so someone else can take it.`);+ }++ // The owner approved an issue: hand it to the first pending claim.+ if (context.eventName === 'issues') {+ if (assignees.length > 0) return;+ const comments = await github.paginate(github.rest.issues.listComments, {+ owner, repo, issue_number: number, per_page: 100,+ });+ let claimer = null;+ for (const c of comments) {+ if (c.user.type !== 'User') continue;+ if (isCommand(c.body, '/claim')) claimer = claimer ?? c.user.login;+ if (isCommand(c.body, '/unclaim') && c.user.login === claimer) claimer = null;+ }+ if (claimer) await assign(claimer);+ return;+ }++ const comment = context.payload.comment;+ const login = comment.user.login;++ if (isCommand(comment.body, '/unclaim')) {+ if (!assignees.includes(login)) return;+ await github.rest.issues.removeAssignees({ owner, repo, issue_number: number, assignees: [login] });+ await reply(`@${login} is no longer assigned. This issue is free to \`/claim\` again.`);+ return;+ }++ if (!isCommand(comment.body, '/claim')) return;++ if (issue.state === 'closed') {+ await reply(`@${login}, this issue is closed, so it can't be claimed.`);+ return;+ }+ if (assignees.includes(login)) return;+ if (assignees.length > 0) {+ await reply(`@${login}, this issue is already assigned to @${assignees[0]}. If it goes quiet for a while, feel free to ask here.`);+ return;+ }+ if (labels().includes(APPROVED)) {+ await assign(login);+ return;+ }++ // Not approved yet: keep the claim and wait for the owner.+ if (!labels().includes(PENDING)) {+ await github.rest.issues.addLabels({ owner, repo, issue_number: number, labels: [PENDING] });+ }+ await reply(`Thanks @${login}! This issue hasn't been approved yet. Your claim is saved: if it gets approved, you'll be assigned automatically. If it isn't approved, it won't be worked on.`);diff --git a/.github/workflows/issue-responder.yml b/.github/workflows/issue-responder.ymlnew file mode 100644index 0000000..b173c78--- /dev/null+++ b/.github/workflows/issue-responder.yml@@ -0,0 +1,32 @@+name: Issue Responder++on:+ issues:+ types: [opened]++jobs:+ respond:+ # Don't answer issues opened by the owner.+ if: github.event.issue.user.login != github.repository_owner+ runs-on: ubuntu-latest+ permissions:+ issues: write+ steps:+ - name: Welcome the author+ uses: actions/github-script@v9+ with:+ script: |+ const issue = context.payload.issue;+ const body = [+ `**Thanks for opening this issue, @${issue.user.login}!** 🙌`,+ '',+ '- **Duplicate?** If there is already an issue about this, please comment there instead (extra details, or just "it happens to me too").',+ '- **Response time:** GymMane is made by a student, so replies can take a while, but every issue gets read. Thanks for your patience!',+ '- **Want to work on it?** Comment `/claim`. If the issue is approved, it is yours; if not, it won\'t be done.',+ ].join('\n');+ await github.rest.issues.createComment({+ owner: context.repo.owner,+ repo: context.repo.repo,+ issue_number: issue.number,+ body,+ });