Skip to content

Commit

Permalink
Initial manipulation of Projects using Milestones (#1178)
Browse files Browse the repository at this point in the history
* 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
Ryan089 authored Apr 19, 2023
1 parent 014f65f commit 618b238
Show file tree
Hide file tree
Showing 5 changed files with 251 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .github/actions/check-milestone-exists/action.yml
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'
12 changes: 12 additions & 0 deletions .github/actions/check-milestone-exists/index.js
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);
61 changes: 61 additions & 0 deletions .github/workflows/CloseProjectWhenMilestoneClosed.yml
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 .github/workflows/CreateProjectWhenMilestoneCreated.yml
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 }}
61 changes: 61 additions & 0 deletions .github/workflows/RenameProjectWhenMilestoneRenamed.yml
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 }}

0 comments on commit 618b238

Please sign in to comment.