setup our own youtube link utils library which will be open sourced #8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Label Pull Request Contributors | |
| on: | |
| pull_request: | |
| types: [opened, synchronize, reopened] | |
| jobs: | |
| label-contributor: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Label PR based on contributor membership | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| console.log(`🔍 Checking membership for user: ${context.payload.pull_request.user.login}`); | |
| console.log(`🏢 Organization: GENWAY-AI`); | |
| console.log(`📋 PR Number: ${context.payload.pull_request.number}`); | |
| let isInternal = false; | |
| const username = context.payload.pull_request.user.login; | |
| // Method 0: Check if user is the repository owner | |
| if (username === context.repo.owner || username === 'tomhipsh') { | |
| console.log(`✅ User is repository owner or known internal user: ${username}`); | |
| isInternal = true; | |
| } else { | |
| try { | |
| // Method 1: Check organization membership | |
| const { data: membership } = await github.rest.orgs.checkMembershipForUser({ | |
| org: 'GENWAY-AI', | |
| username: username | |
| }); | |
| console.log(`✅ Organization membership check successful:`, membership); | |
| isInternal = true; | |
| } catch (orgError) { | |
| console.log(`❌ Organization membership check failed:`, orgError.message); | |
| console.log(`📊 Error status:`, orgError.status); | |
| try { | |
| // Method 2: Check if user is a repository collaborator | |
| const { data: collaborator } = await github.rest.repos.checkCollaborator({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| username: username | |
| }); | |
| console.log(`✅ Collaborator check successful:`, collaborator); | |
| isInternal = true; | |
| } catch (collabError) { | |
| console.log(`❌ Collaborator check also failed:`, collabError.message); | |
| console.log(`📊 Collaborator error status:`, collabError.status); | |
| try { | |
| // Method 3: Check repository permissions directly | |
| const { data: permission } = await github.rest.repos.getCollaboratorPermissionLevel({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| username: username | |
| }); | |
| console.log(`✅ Permission level check:`, permission); | |
| // If user has write, maintain, or admin access, they're internal | |
| if (['write', 'maintain', 'admin'].includes(permission.permission)) { | |
| isInternal = true; | |
| console.log(`✅ User has ${permission.permission} access - treating as internal`); | |
| } | |
| } catch (permError) { | |
| console.log(`❌ Permission check also failed:`, permError.message); | |
| } | |
| } | |
| } | |
| } | |
| if (isInternal) { | |
| // Internal contributor - add internal label | |
| await github.rest.issues.addLabels({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.payload.pull_request.number, | |
| labels: ['internal-contributor'] | |
| }); | |
| console.log(`✅ PR from internal contributor: ${context.payload.pull_request.user.login}`); | |
| } else { | |
| // External contributor - add external label | |
| await github.rest.issues.addLabels({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.payload.pull_request.number, | |
| labels: ['external-contributor'] | |
| }); | |
| // Welcome external contributors with helpful message | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.payload.pull_request.number, | |
| body: '👋 Welcome External Contributor! Thank you for your contribution to youtube-link-utils! Your PR will be reviewed by GENWAY-AI organization members before merging.' | |
| }); | |
| console.log(`🔍 PR from external contributor: ${context.payload.pull_request.user.login}`); | |
| } |