Skip to content

Commit 8f571e9

Browse files
committed
Changed org membership check to use author_association
- Use PR's author_association field to check org membership - Removed redundant API call to check membership status - Pass author_association as parameter to isGhostFoundationMember - Keep Admin repo permission check to identify core team members
1 parent 54ffbd9 commit 8f571e9

File tree

3 files changed

+26
-42
lines changed

3 files changed

+26
-42
lines changed

actions/label-actions/dist/index.js

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9933,12 +9933,8 @@ module.exports = class Helpers {
99339933
/**
99349934
* Check if a GitHub user is a core team member
99359935
*
9936-
* Note: We previously tried using team membership checks, but the GITHUB_TOKEN
9937-
* used in Actions cannot access team membership data, even for "visible"
9938-
* (non-secret) teams. This is a GitHub limitation.
9939-
*
9940-
* Instead, we identify core team members by:
9941-
* 1. Being a member of the TryGhost organization AND
9936+
* We identify core team members by:
9937+
* 1. Being a member of the TryGhost organization (checked via author_association)
99429938
* 2. Having write or admin access to the Admin repository
99439939
*
99449940
* This approach correctly distinguishes between:
@@ -9947,23 +9943,18 @@ module.exports = class Helpers {
99479943
* - Community (not org member)
99489944
*
99499945
* @param {string} username
9946+
* @param {string} authorAssociation The PR author's association with the repository
99509947
* @returns {Promise<boolean>}
99519948
*/
9952-
async isGhostFoundationMember(username) {
9949+
async isGhostFoundationMember(username, authorAssociation) {
99539950
try {
9954-
// First check org membership
9955-
try {
9956-
await this.client.rest.orgs.checkMembershipForUser({
9957-
org: 'TryGhost',
9958-
username: username
9959-
});
9960-
core.info(`User ${username} is a member of TryGhost org`);
9961-
} catch (err) {
9962-
if (err.status === 404) {
9963-
core.info(`User ${username} is not a member of TryGhost org`);
9964-
return false;
9965-
}
9966-
throw err;
9951+
// First check if they're an org member using author_association
9952+
const isOrgMember = ['OWNER', 'MEMBER'].includes(authorAssociation);
9953+
core.info(`User ${username} has ${authorAssociation} association with the repository`);
9954+
9955+
if (!isOrgMember) {
9956+
core.info('User is not an organization member');
9957+
return false;
99679958
}
99689959

99699960
// If they're an org member, check Admin repo permissions
@@ -10261,6 +10252,7 @@ async function main() {
1026110252
if (payload.action === 'opened') {
1026210253
const pullRequest = payload.pull_request;
1026310254
const author = pullRequest.user.login;
10255+
core.info(`PR opened #${pullRequest.number} by ${author} (${pullRequest.state}, ${pullRequest.author_association})`);
1026410256

1026510257
// Check if this is a dependency bot PR (e.g., Renovate, Dependabot)
1026610258
const isDependencyBot = (pullRequest.user.type === 'Bot' || author.includes('[bot]') || author === 'renovate-bot') &&
@@ -10274,7 +10266,7 @@ async function main() {
1027410266
core.info(`Skipping labeling for bot PR #${pullRequest.number} by ${author}`);
1027510267
} else {
1027610268
// Check if the PR author is a member of the Ghost Foundation team
10277-
const isGhostMember = await helpers.isGhostFoundationMember(author);
10269+
const isGhostMember = await helpers.isGhostFoundationMember(author, pullRequest.author_association);
1027810270

1027910271
// Add appropriate label based on membership
1028010272
if (isGhostMember) {

actions/label-actions/src/helpers.js

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,8 @@ module.exports = class Helpers {
245245
/**
246246
* Check if a GitHub user is a core team member
247247
*
248-
* Note: We previously tried using team membership checks, but the GITHUB_TOKEN
249-
* used in Actions cannot access team membership data, even for "visible"
250-
* (non-secret) teams. This is a GitHub limitation.
251-
*
252-
* Instead, we identify core team members by:
253-
* 1. Being a member of the TryGhost organization AND
248+
* We identify core team members by:
249+
* 1. Being a member of the TryGhost organization (checked via author_association)
254250
* 2. Having write or admin access to the Admin repository
255251
*
256252
* This approach correctly distinguishes between:
@@ -259,23 +255,18 @@ module.exports = class Helpers {
259255
* - Community (not org member)
260256
*
261257
* @param {string} username
258+
* @param {string} authorAssociation The PR author's association with the repository
262259
* @returns {Promise<boolean>}
263260
*/
264-
async isGhostFoundationMember(username) {
261+
async isGhostFoundationMember(username, authorAssociation) {
265262
try {
266-
// First check org membership
267-
try {
268-
await this.client.rest.orgs.checkMembershipForUser({
269-
org: 'TryGhost',
270-
username: username
271-
});
272-
core.info(`User ${username} is a member of TryGhost org`);
273-
} catch (err) {
274-
if (err.status === 404) {
275-
core.info(`User ${username} is not a member of TryGhost org`);
276-
return false;
277-
}
278-
throw err;
263+
// First check if they're an org member using author_association
264+
const isOrgMember = ['OWNER', 'MEMBER'].includes(authorAssociation);
265+
core.info(`User ${username} has ${authorAssociation} association with the repository`);
266+
267+
if (!isOrgMember) {
268+
core.info('User is not an organization member');
269+
return false;
279270
}
280271

281272
// If they're an org member, check Admin repo permissions

actions/label-actions/src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ async function main() {
6767
if (payload.action === 'opened') {
6868
const pullRequest = payload.pull_request;
6969
const author = pullRequest.user.login;
70+
core.info(`PR opened #${pullRequest.number} by ${author} (${pullRequest.state}, ${pullRequest.author_association})`);
7071

7172
// Check if this is a dependency bot PR (e.g., Renovate, Dependabot)
7273
const isDependencyBot = (pullRequest.user.type === 'Bot' || author.includes('[bot]') || author === 'renovate-bot') &&
@@ -80,7 +81,7 @@ async function main() {
8081
core.info(`Skipping labeling for bot PR #${pullRequest.number} by ${author}`);
8182
} else {
8283
// Check if the PR author is a member of the Ghost Foundation team
83-
const isGhostMember = await helpers.isGhostFoundationMember(author);
84+
const isGhostMember = await helpers.isGhostFoundationMember(author, pullRequest.author_association);
8485

8586
// Add appropriate label based on membership
8687
if (isGhostMember) {

0 commit comments

Comments
 (0)