forked from dev-academy-programme/waffler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
80 lines (69 loc) · 2.21 KB
/
index.js
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
var Promise = require("bluebird")
var GitHubApi = require('github')
var prompt = require("prompt")
var collateAndPushAssignments = require('./collate-push-assignments')
var createIssueLabels = require('./create-issue-labels')
var patchAssignments = require('./patch-assignments')
var consoleHelp = require('./console-help')
var github = new GitHubApi({
version: "3.0.0",
debug: false,
protocol: "https",
})
var githubReposAsync = Promise.promisifyAll(github.repos)
// collect user input
var action = process.argv[2]
function waffle() {
if (action === "push") {
var sprintNum = process.argv[3].match(/\d/)
var githubCohortRepoName = process.argv[4]
var studentGithubUsername = process.argv[5]
var assignmentsFolder = process.argv[6]
authenticateGithub()
collateAndPushAssignments(sprintNum, githubCohortRepoName, studentGithubUsername, assignmentsFolder, githubReposAsync, github)
} else if (action === "label") {
var githubCohortRepoName = process.argv[3]
authenticateGithub()
createIssueLabels(githubCohortRepoName, github)
} else if (action === "patch") {
// waffle patch moa-2010 1.4 "skjdskljdsaf" "afkljadfslkj"
var githubCohortRepoName = process.argv[3]
var assignmentTitleSearch = process.argv[4]
var findTerm = process.argv[5]
var replaceTerm = process.argv[6]
authenticateGithub()
patchAssignments(githubCohortRepoName, assignmentTitleSearch, findTerm, replaceTerm, github)
} else {
consoleHelp()
}
}
function authenticateGithub() {
if (!!process.env.GITHUB_USERNAME && !!process.env.GITHUB_PASSWORD) {
authenticateSession(process.env.GITHUB_USERNAME,process.env.GITHUB_PASSWORD)
} else {
prompt.start()
var schema = {
properties: {
githubUsername: {
required: true
},
githubPassword: {
required: true,
hidden: true
}
}
};
prompt.get(schema, function(err, result) {
if (err) { throw err }
authenticateSession(result.githubUsername, result.githubPassword)
})
}
}
function authenticateSession(githubUsername, githubPassword) {
github.authenticate({
type: "basic",
username: githubUsername,
password: githubPassword
})
}
module.exports = waffle