-
Notifications
You must be signed in to change notification settings - Fork 5
156 lines (128 loc) · 5.96 KB
/
action-clone-and-create-new-project.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
name: Clone an existing Project Board
on:
workflow_dispatch:
inputs:
projectID:
description: "Specify the unique Project ID of project that will be copied from"
default: "13621042"
required: true
descNewProject:
description: "Provide type your GitHub name"
default: "@USERNAME"
required: true
permissions:
actions: none
checks: none
contents: none
deployments: none
issues: none
packages: none
pull-requests: none
repository-projects: write
security-events: none
statuses: none
env:
PROJECT_ID: ${{ github.event.inputs.projectID }}
jobs:
newProject:
runs-on: ubuntu-latest
steps:
- name: Test
uses: actions/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
previews: 'inertia' # required for Projects API
script: |
console.log("======= Starting to get the data from an existing Project Board with ID: " + ${{ env.PROJECT_ID }} + " ==============")
// RETRIEVE the Columns from the existing Project Board:
try {
listColumns = await github.projects.listColumns({
project_id: ${{ env.PROJECT_ID }}
})
} catch(err) {
throw err
}
console.log("Discovered a total of " + listColumns.length + " in the Project Board with ID: " + ${{ env.PROJECT_ID }})
// REPRESENTING the Column IDs associated with existing Project Board - used to get all cards in the column:
listColumnIDs = []
// REPRESENTING the title in each column associated with existing Project Board:
listColumnNames = []
// ITERATING through the columns to extract IDs and titled:
listColumns.data.forEach(function(column) {
listColumnIDs.push(column.id)
listColumnNames.push(column.name)
})
// REPRSENTING the list of unfiltered Card data directly pulled from GitHub API:
listAllCardsUnformatted = []
// ITERATING through the Columns to extract the Card data:
try {
for(var i=0; i < listColumnIDs.length; ++ i) {
listCards4Column = await github.projects.listCards({
column_id: listColumnIDs[i]
})
listAllCardsUnformatted.push(listCards4Column.data)
}
} catch(err) {
throw err
}
// REPRESENTING the list of all cards with only Note copied from each Card:
listAllCards = []
// ITERATING to create a new nested list representing all cards per column:
listAllCardsUnformatted.forEach(function(cardsPerColumn) {
listCardsPerColumn = []
// ITERATING through all cards in this column:
cardsPerColumn.forEach(function(card) {
listCardsPerColumn.push(card.note ? card.note : card.content_id)
})
// STORING the reversed card orders since it is ordered in an opposite way:
listAllCards.push(listCardsPerColumn.reverse())
})
console.log("What is inside the existing Project Board => " + JSON.stringify(listAllCards))
// REPRESENTING the length of columns:
nListColumns = listAllCards.length;
console.log("\n========= Let's create a new Project! ==================\n")
// REPRESENTING a new Project Board:
var projectObj="";
// CREATE a new Project Board based on input:
try {
projectObj = await github.projects.createForRepo({
owner: context.payload.organization.login,
repo: context.payload.repository.name,
name: "${{ github.event.inputs.descNewProject }} Daily survival plan at GitHub Actions planet"
})
} catch(err) {
throw err
}
console.log("New Project was created with Project ID: " + projectObj.data.id)
console.log("Next, we will now create cards and columns")
// ITERATING to create Cards for a new Project Board:
for(var iColumn=0; iColumn < nListColumns; ++ iColumn) {
try {
// CREATE a new column attached to our new project ID:
var columnObj = await github.projects.createColumn({
name: listColumnNames[iColumn],
project_id: projectObj.data.id
})
// REPRESENTING the total number of Cards for this column:
nCardsPerColumn = listAllCards[iColumn].length
// REPRESENTING the content of Cards in this column:
listOrderedCardsPerColumn = listAllCards[iColumn]
console.log("Cards in this column: " + JSON.stringify(listOrderedCardsPerColumn))
// ITERATING to create Cards for this column:
for(var iCard = 0; iCard < nCardsPerColumn; ++ iCard) {
try {
var cardObj = await github.projects.createCard({
column_id: columnObj.data.id,
note: listOrderedCardsPerColumn[iCard]
})
} catch(err) {
console.log("Error in creating card: " + err);
throw err;
}
}
} catch(err) {
console.log("Error in general: " + err);
throw err
}
}
console.log("All done!")