Skip to content
Merged
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
44 changes: 4 additions & 40 deletions add-to-project/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ name: "Add to Project"
description: "Add new issue or pull request to the project"
inputs:
token:
description: "GitHub token"
description: "GitHub token with project write and repository read access"
required: true
type: string
project-url:
Expand All @@ -28,44 +28,8 @@ runs:
using: "composite"
steps:
- name: Adding to project
uses: actions/github-script@v8
shell: bash
env:
GH_TOKEN: ${{ inputs.token }}
PROJECT_URL: ${{ inputs.project-url }}
with:
github-token: ${{ inputs.token }}
script: |
const projectUrl = process.env.PROJECT_URL;
const match = projectUrl.match(/\/(?<ownerType>orgs|users)\/(?<ownerName>[^/]+)\/projects\/(?<projectNumber>\d+)/);
if (!match) {
core.setFailed(`Invalid project URL: ${projectUrl}`);
return;
}
const { ownerType, ownerName, projectNumber } = match.groups;

// Get the project node ID
const ownerField = ownerType === 'orgs' ? 'organization' : 'user';
const { [ownerField]: owner } = await github.graphql(`
query($ownerName: String!, $projectNumber: Int!) {
${ownerField}(login: $ownerName) {
projectV2(number: $projectNumber) { id }
}
}
`, { ownerName, projectNumber: parseInt(projectNumber) });
const projectId = owner.projectV2.id;

// Get the content node ID (issue or pull request)
const contentId = context.payload.issue?.node_id || context.payload.pull_request?.node_id;
if (!contentId) {
core.setFailed('No issue or pull request found in event payload.');
return;
}

await github.graphql(`
mutation($projectId: ID!, $contentId: ID!) {
addProjectV2ItemById(input: {projectId: $projectId, contentId: $contentId}) {
item { id }
}
}
`, { projectId, contentId });

core.info(`Added to project ${projectUrl}`);
run: python3 "${{ github.action_path }}/add_to_project.py"
Comment thread
YanxuanLiu marked this conversation as resolved.
Loading