forked from pkgjs/meet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.js
More file actions
155 lines (137 loc) · 4.68 KB
/
Copy pathrun.js
File metadata and controls
155 lines (137 loc) · 4.68 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
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
'use strict'
const core = require('@actions/core')
const { getOctokit, context } = require('@actions/github')
const list = require('safe-parse-list')
const ejs = require('ejs')
const meetings = require('./lib/meetings')
const issues = require('./lib/issues')
const notes = require('./lib/notes')
const defaultTemplate = require('./lib/default-template')
const defaultNotesTemplate = require('./lib/default-notes-template')
const conversions = require('./lib/conversions')
const agenda = require('./lib/agenda')
const pkg = require('./package.json')
;(async function run () {
console.log(`Version: ${pkg.version}`)
try {
const token = core.getInput('token')
const client = getOctokit(token)
// variables we use for timing
const schedules = list(core.getInput('schedules'))
const createWithin = core.getInput('createWithin')
const timezone = core.getInput('timezone')
// variables we use for labels
const agendaLabel = core.getInput('agendaLabel')
const meetingLabels = core.getInput('meetingLabels')
// variables we use for content
const issueTitle = core.getInput('issueTitle')
const issueTemplate = core.getInput('issueTemplate')
// variables we use for notes
const createNotes = core.getInput('createNotes')
const notesUserTemplate = core.getInput('notesTemplate')
const meetingLink = core.getInput('meetingLink')
// Get list of repos
let repos = core.getInput('repos')
const repo = context.repo
if (repos) {
repos = repos.split(',').map((str) => {
const parts = str.trim().split('/')
return {
owner: parts[0],
repo: parts[1]
}
})
} else {
repos = [context.repo]
}
// Get repos from orgs
let orgs = core.getInput('orgs')
if (orgs) {
orgs = orgs.split(',').map((o) => o.trim())
for (const org of orgs) {
console.log(`Fetching repos for ${org}`)
const resp = await client.paginate('GET /orgs/{org}/repos', { org })
resp.forEach((r) => {
repos.push({
owner: org,
repo: r.name
})
})
}
}
let template = defaultTemplate
// if we have a user-provided issue template, try to get it
// and then if it exists reassign template variable from the
// default to the user-provided template
if (issueTemplate) {
try {
const userProvidedIssueTemplate = await issues.stringifiedIssueTemplate(client, {
...repo,
template: issueTemplate,
ref: context.payload?.pull_request?.head?.ref || context.payload?.repository?.default_branch || 'main'
})
template = conversions.convert(userProvidedIssueTemplate)
template = ejs.compile(userProvidedIssueTemplate)
} catch (error) {
console.error(`template missing or invalid (${issueTemplate}): ${error.message}`)
}
}
let titleTemplate = issueTitle
if (issueTemplate) {
try {
titleTemplate = ejs.compile(titleTemplate)
} catch (e) {
// ignore title template
}
}
const agendaIssues = await agenda.fetchAgendaItems(client, repos, agendaLabel)
const opts = {
...repo,
schedules,
timezone,
meetingLabels,
createWithin,
agendaLabel,
meetingLink,
agendaIssues,
issueTitle: titleTemplate
}
const issue = await meetings.createNextMeeting(client, { ...opts, template })
if (!issue) {
return console.log('No issues to create')
}
const issueNumber = issue.data.number
core.setOutput('issueNumber', issueNumber.toString())
console.log(`Issue created: (#${issueNumber}) ${issue.data.title}`)
opts.issue = issue.data
if (createNotes === true || createNotes === 'true') {
let notesTemplate = defaultNotesTemplate
if (notesUserTemplate) {
try {
const tmpl = await notes.getNotesTemplate(client, {
...repo,
notesUserTemplate
})
notesTemplate = ejs.compile(tmpl)
} catch (e) {
console.error(`notesTemplate missing or invalid (${notesUserTemplate}): ${e.message}`)
}
}
opts.meetingNotes = await notes.create(notesTemplate, opts)
if (opts.meetingNotes) {
console.log(`notes created: ${opts.meetingNotes}`)
} else {
console.log('notes creation failed; continuing without notes')
}
}
const updatedIssue = await meetings.setMeetingIssueBody(client, { ...opts, template })
if (!updatedIssue) {
return console.log('No issues to update')
} else {
return console.log('Issue updated successfully')
}
} catch (e) {
console.error(e)
core.setFailed(e.message)
}
})()