Skip to content
Open
Changes from 1 commit
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
45 changes: 30 additions & 15 deletions .github/workflows/org-invite-codeheat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,20 @@ jobs:
TEAM_SLUG: "codeheat"

steps:
- name: Debug secret presence
run: |
if [ -z "${{ secrets.ORG_ADMIN_TOKEN }}" ]; then
echo "❌ ORG_ADMIN_TOKEN is NOT available"
exit 1
else
echo "✅ ORG_ADMIN_TOKEN is available"
fi

- name: Invite user to org and team
uses: actions/github-script@v7
with:
github-token: ${{ secrets.ORG_ADMIN_TOKEN }}
script: |
// Validate that the token is present
if (!github.token || github.token.trim() === "") {
throw new Error("ORG_ADMIN_TOKEN is missing or empty. Please set the required secret.");
}
const org = process.env.ORG_NAME;
const team_slug = process.env.TEAM_SLUG;
const issue = context.payload.issue;
Expand Down Expand Up @@ -71,18 +76,22 @@ jobs:

// ---- Org membership ----
let membership;
let invited = false;

try {
membership = await github.rest.orgs.getMembershipForUser({
org,
username,
});
} catch (error) {
if (error.status !== 404) throw error;

membership = await github.rest.orgs.setMembershipForUser({
org,
username
username,
});
} catch (err) {
await comment(
`❌ **Failed to invite @${username} to ${org}**\n\n` +
`Error: ${err.message}`
);
core.setFailed(err.message);
return;

invited = true;
}

// ---- Team membership (non-fatal) ----
Expand All @@ -99,15 +108,21 @@ jobs:
);
}

const orgStatusLine = invited
? `• Org invitation: **${membership.data.state}**\n`
: `• Org membership: **already active**\n`;
Comment on lines +131 to +133
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): Org membership text can be incorrect for existing but pending members.

When getMembershipForUser returns state === 'pending' for an existing membership, invited stays false, so orgStatusLine becomes "• Org membership: **already active**", even though the later actionMessage logic correctly treats this as pending. Please derive orgStatusLine from membership.data.state in both cases (or at least special-case pending when invited === false) so the status text matches the actual membership state.


const teamStatusLine = teamMembership
? `• Team membership: **${teamMembership.data.state}**\n`
: `• Team membership: ❌ **failed** - please add manually to \`${team_slug}\`\n`;

await comment(
`✅ **Onboarding processed for @${username}**\n\n` +
`• Org membership: **${membership.data.state}**\n` +
`✅ **Onboarding request processed for @${username}**\n\n` +
orgStatusLine +
teamStatusLine +
`\nIf any status is **pending**, please accept the GitHub invitation.`
(invited
? `\nℹ️ Please accept the GitHub invitation from your notifications or email.`
: `\nℹ️ You are already a member. No further action is required.`)
);

// ---- Close issue (non-fatal) ----
Expand Down