Skip to content
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

👷 Add GitHub Actions workflow for automated invitations #53

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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/invite.yml
Copy link

@vacaramin vacaramin Jul 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be much better if you just used a community action for this based on label. and alongside, add an issue template for easy onboarding.
Similar to Voninc | Become a Member

 Invite_to_Organization:
    runs-on: ubuntu-latest
    needs: Dump_Github_Context
    steps:
      - name: Invite on label
        uses: vj-abigo/[email protected]
        with:
          organization: Voninc
          label: invitation
          repo-token: ${{ secrets.GITHUB_TOKEN }}
          comment: 'Invitation has been sent'
        env:
          INVITE_TOKEN: ${{ secrets.TOKEN }}
          ```

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Invite CI
on:
issues:
types: [opened, edited]
jobs:
invite:
name: Send invites
runs-on: ubuntu-18.04
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: lts/*
- name: Install dependencies
uses: bahmutov/npm-install@v1
- name: Build TypeScript
run: npm run build
- name: Run script
run: npm run start
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
71 changes: 71 additions & 0 deletions action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { debug, getInput, setFailed, setOutput } from "@actions/core";
import { getOctokit } from "@actions/github";

const token =
getInput("token") || process.env.GH_PAT || process.env.GITHUB_TOKEN;

export const run = async () => {
if (!token) throw new Error("GitHub token not found");
const octokit = getOctokit(token);
const owner = (process.env.GITHUB_REPOSITORY || "").split("/")[0];
const repo = (process.env.GITHUB_REPOSITORY || "").split("/")[1];
debug(`Got repo ${owner}/${repo}`);

const invitations = await octokit.paginate(
octokit.rest.orgs.listPendingInvitations,
{ org: owner }
);

const issues = await octokit.paginate(octokit.rest.issues.listForRepo, {
owner,
repo,
state: "open",
});
for (const issue of issues) {
if (issue.title.toLowerCase().trim() !== "join") {
debug(`${issue.number}: Skipped because title is not "Join"`);
continue;
}

if (!issue.user) {
debug(`${issue.number}: Skipped because no user found`);
continue;
}

debug(`${issue.number}: Processing`);
if (invitations.find((i) => i.login === (issue.user || {}).login)) {
debug(`${issue.number}: Skipped because invitation already sent`);
continue;
}

await octokit.rest.orgs.createInvitation({
org: owner,
invitee_id: issue.user.id,
});
debug(`${issue.number}: Sent invitation`);
await octokit.rest.issues.createComment({
owner,
repo,
issue_number: issue.number,
body: `✅🇪🇺 You should receive an invitation to join @eu soon. Welcome!`,
});
debug(`${issue.number}: Added welcome comment`);
await octokit.rest.issues.update({
owner,
repo,
issue_number: issue.number,
state: "closed",
});
debug(`${issue.number}: Closed`);
}

setOutput("issues-count", issues.length);
setOutput("invitations-count", invitations.length);
};

run()
.then(() => {})
.catch((error) => {
console.error("ERROR", error);
setFailed(error.message);
});
24 changes: 0 additions & 24 deletions list.txt

This file was deleted.

Loading