-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
65 lines (56 loc) · 2.15 KB
/
Copy pathmain.ts
File metadata and controls
65 lines (56 loc) · 2.15 KB
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
import * as core from '@actions/core'
import { Octokit } from '@octokit/rest'
import * as fs from 'fs'
import path from 'path'
import * as actions from './actions.js'
import { AllowedAction } from './enums.js'
import { generateRepoName } from './github/repos.js'
import { getClassroom, getInputs, updateClassroom } from './inputs.js'
export async function run(): Promise<void> {
// Check if the GITHUB_TOKEN environment variable is set.
if (!process.env.GITHUB_TOKEN) {
core.error('GITHUB_TOKEN Environment Variable Not Set')
return
}
const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN!,
log: {
debug: (message: string) => {},
info: (message: string) => {},
warn: (message: string) => {},
error: (message: string) => {}
}
})
// Get the command-line inputs. Exit if not present.
const inputs = getInputs()
if (!inputs) return
// Get the classroom JSON file. Exit if not present.
const classroom = getClassroom()
if (!classroom) return
try {
core.info(`Processing Action: ${inputs.action}`)
core.info('')
if (inputs.action === AllowedAction.CREATE)
await actions.createClass(octokit, classroom)
else if (inputs.action === AllowedAction.CLOSE)
await actions.closeClass(octokit, classroom)
else if (inputs.action === AllowedAction.ADD_USER)
await actions.addUser(octokit, classroom, inputs.handle!)
else if (inputs.action === AllowedAction.REMOVE_USER)
await actions.removeUser(octokit, classroom, inputs.handle!)
else if (inputs.action === AllowedAction.ADD_ADMIN)
await actions.addAdmin(octokit, classroom, inputs.handle!)
else if (inputs.action === AllowedAction.REMOVE_ADMIN)
await actions.removeAdmin(octokit, classroom, inputs.handle!)
updateClassroom(classroom)
/* istanbul ignore next */
for (const user of [...classroom.attendees, ...classroom.administrators]) {
const repoName = generateRepoName(classroom, user)
const repoPath = path.join(process.cwd(), repoName)
if (fs.existsSync(repoPath))
fs.rmSync(repoPath, { recursive: true, force: true })
}
} catch (error: any) {
core.error(error)
}
}