-
-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial manipulation of Projects using Milestones (#1178)
* Initial manipulation of Projects using Milestones (create, rename, close) * Creates the project as a public project, and links it to the SS3D repo.
- Loading branch information
Showing
5 changed files
with
251 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: 'Check milestone exists' | ||
inputs: | ||
JSON_LIST_OF_PROJECTS: | ||
description: 'Results of a GraphQL query returning all ProjectV2 owned by RE-SS3D.' | ||
required: true | ||
PROJECT_NAME: | ||
description: 'The name of the project to search for.' | ||
required: true | ||
outputs: | ||
EXISTING_PROJECT_ID: | ||
description: 'String containing the project ID that matches the provided project name. Blank string if not found.' | ||
runs: | ||
using: 'node16' | ||
main: 'index.js' |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const core = require('@actions/core'); | ||
const results = JSON.parse(core.getInput('JSON_LIST_OF_PROJECTS')) | ||
const target = core.getInput('PROJECT_NAME').toUpperCase() | ||
|
||
var existingProjectId = null | ||
for (let i = 0; i < results.organization.projectsV2.nodes.length; i++) { | ||
console.log( results.organization.projectsV2.nodes[i].title.toUpperCase() ) | ||
if (target == results.organization.projectsV2.nodes[i].title.toUpperCase()) { | ||
existingProjectId = results.organization.projectsV2.nodes[i].id | ||
} | ||
} | ||
core.setOutput('EXISTING_PROJECT_ID', existingProjectId); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
name: Close Project When Milestone Closed | ||
on: | ||
milestone: | ||
types: [closed] | ||
jobs: | ||
CloseProjectWhenMilestoneClosed: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Setup node | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '16' | ||
- run: npm install @actions/core | ||
- run: npm install @actions/github | ||
- name: Get list of projects | ||
uses: octokit/[email protected] | ||
id: get-project-title | ||
with: | ||
query: | | ||
query getTitle( $org:String!) { | ||
organization(login:$org) { | ||
projectsV2(first:100) { | ||
nodes { | ||
id | ||
title | ||
number | ||
template | ||
closed | ||
owner { | ||
id | ||
} | ||
} | ||
} | ||
} | ||
} | ||
org: RE-SS3D | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.PROJECT_MANAGEMENT_TOKEN }} | ||
- name: Check for existence of milestone project | ||
uses: ./.github/actions/check-milestone-exists | ||
id: check-milestone-exists | ||
with: | ||
JSON_LIST_OF_PROJECTS: ${{ steps.get-project-title.outputs.data }} | ||
PROJECT_NAME: ${{ github.event.milestone.title }} | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.PROJECT_MANAGEMENT_TOKEN }} | ||
- name: Close Project | ||
uses: octokit/[email protected] | ||
id: close-project | ||
if: ${{ steps.check-milestone-exists.outputs.EXISTING_PROJECT_ID != ''}} | ||
with: | ||
query: | | ||
mutation CloseTheProject { | ||
updateProjectV2(input: {projectId:"${{ steps.check-milestone-exists.outputs.EXISTING_PROJECT_ID }}", closed:true }) { | ||
clientMutationId | ||
} | ||
} | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.PROJECT_MANAGEMENT_TOKEN }} |
103 changes: 103 additions & 0 deletions
103
.github/workflows/CreateProjectWhenMilestoneCreated.yml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
name: Create Project When Milestone Created | ||
on: | ||
milestone: | ||
types: [created] | ||
jobs: | ||
CreateProjectFromMilestone: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Setup node | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '16' | ||
- run: npm install @actions/core | ||
- run: npm install @actions/github | ||
- name: Get list of projects | ||
uses: octokit/[email protected] | ||
id: get-project-title | ||
with: | ||
query: | | ||
query getTitle( $org:String!) { | ||
organization(login:$org) { | ||
projectsV2(first:100) { | ||
nodes { | ||
id | ||
title | ||
number | ||
template | ||
closed | ||
owner { | ||
id | ||
} | ||
} | ||
} | ||
} | ||
} | ||
org: RE-SS3D | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.PROJECT_MANAGEMENT_TOKEN }} | ||
- name: Check for existence of milestone project | ||
uses: ./.github/actions/check-milestone-exists | ||
id: check-milestone-exists | ||
with: | ||
JSON_LIST_OF_PROJECTS: ${{ steps.get-project-title.outputs.data }} | ||
PROJECT_NAME: ${{ github.event.milestone.title }} | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.PROJECT_MANAGEMENT_TOKEN }} | ||
- name: Duplicate Template Project | ||
uses: octokit/[email protected] | ||
id: duplicate-template-project | ||
if: ${{ steps.check-milestone-exists.outputs.EXISTING_PROJECT_ID == '' }} | ||
with: | ||
query: | | ||
mutation copyTheProject { | ||
copyProjectV2(input: {ownerId:"MDEyOk9yZ2FuaXphdGlvbjQyNzc4NjQw", projectId:"PVT_kwDOAozAEM4AMVn2", title:"Example"}) { | ||
clientMutationId | ||
projectV2 { | ||
id | ||
} | ||
} | ||
} | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.PROJECT_MANAGEMENT_TOKEN }} | ||
- name: Setup Project | ||
uses: octokit/[email protected] | ||
id: setup-project | ||
if: ${{ steps.check-milestone-exists.outputs.EXISTING_PROJECT_ID == ''}} | ||
with: | ||
query: | | ||
mutation setupTheProject { | ||
updateProjectV2(input: {projectId:"${{ fromJSON(steps.duplicate-template-project.outputs.data).copyProjectV2.projectV2.id }}", title:"${{ github.event.milestone.title }}", public:true}) { | ||
clientMutationId | ||
} | ||
} | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.PROJECT_MANAGEMENT_TOKEN }} | ||
- name: Get repo ID | ||
uses: octokit/[email protected] | ||
id: get-repo-id | ||
with: | ||
query: | | ||
query getRepo( $org:String!) { | ||
repository(name:"SS3D", owner:$org) { | ||
id | ||
} | ||
} | ||
org: RE-SS3D | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.PROJECT_MANAGEMENT_TOKEN }} | ||
- name: Link SS3D Repository to new Project | ||
uses: octokit/[email protected] | ||
id: link-project | ||
if: ${{ steps.check-milestone-exists.outputs.EXISTING_PROJECT_ID == ''}} | ||
with: | ||
query: | | ||
mutation LinkTheProject { | ||
linkProjectV2ToRepository(input: {projectId:"${{ fromJSON(steps.duplicate-template-project.outputs.data).copyProjectV2.projectV2.id }}", repositoryId:"${{ fromJSON(steps.get-repo-id.outputs.data).repository.id }}" }) { | ||
clientMutationId | ||
} | ||
} | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.PROJECT_MANAGEMENT_TOKEN }} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
name: Rename Project When Milestone Renamed | ||
on: | ||
milestone: | ||
types: [edited] | ||
jobs: | ||
RenameProject: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Setup node | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '16' | ||
- run: npm install @actions/core | ||
- run: npm install @actions/github | ||
- name: Get list of projects | ||
uses: octokit/[email protected] | ||
id: get-project-title | ||
with: | ||
query: | | ||
query getTitle( $org:String!) { | ||
organization(login:$org) { | ||
projectsV2(first:100) { | ||
nodes { | ||
id | ||
title | ||
number | ||
template | ||
closed | ||
owner { | ||
id | ||
} | ||
} | ||
} | ||
} | ||
} | ||
org: RE-SS3D | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.PROJECT_MANAGEMENT_TOKEN }} | ||
- name: Check for existence of milestone project | ||
uses: ./.github/actions/check-milestone-exists | ||
id: check-milestone-exists | ||
with: | ||
JSON_LIST_OF_PROJECTS: ${{ steps.get-project-title.outputs.data }} | ||
PROJECT_NAME: ${{ github.event.changes.title.from }} | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.PROJECT_MANAGEMENT_TOKEN }} | ||
- name: Rename Project | ||
uses: octokit/[email protected] | ||
id: rename-project | ||
if: ${{ steps.check-milestone-exists.outputs.EXISTING_PROJECT_ID != ''}} | ||
with: | ||
query: | | ||
mutation RenameTheProject { | ||
updateProjectV2(input: {projectId:"${{ steps.check-milestone-exists.outputs.EXISTING_PROJECT_ID }}", title:"${{ github.event.milestone.title }}" }) { | ||
clientMutationId | ||
} | ||
} | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.PROJECT_MANAGEMENT_TOKEN }} |