|
1 | 1 | import * as core from '@actions/core'
|
| 2 | +import { match } from 'assert' |
2 | 3 | import axios from 'axios'
|
| 4 | + |
| 5 | +const actionItemsRegEx = new RegExp( |
| 6 | + `Action items\n[-]+\n([\s\S]*?)\nPeople Present`, |
| 7 | + 'm' |
| 8 | +) |
| 9 | +const meetingListRegEx = new RegExp( |
| 10 | + `(?<=>fedora-coreos-meeting.)(.*?)=?txt`, |
| 11 | + `g` |
| 12 | +) |
| 13 | +const folderRegex = new RegExp( |
| 14 | + `/<img src="\/icons\/folder.gif" alt="\[DIR\]"> <a href="([^"]+)\/">/`, |
| 15 | + `g` |
| 16 | +) |
| 17 | +const meetingNotesRootURL = core.getInput('rootURLMeetingLogs') |
| 18 | + |
3 | 19 | export async function GetActionItems(): Promise<string> {
|
4 | 20 | try {
|
5 |
| - console.log(`GetActionItems started`) |
6 |
| - // Set constants |
7 |
| - const actionItemsRegEx = new RegExp( |
8 |
| - `(?<=Action Items\n------------\n)((.|\n)*)(?=Action Items,)` |
9 |
| - ) |
10 |
| - const meetingListRegEx = new RegExp( |
11 |
| - `(?<=>fedora-coreos-meeting.)(.*?)=?txt`, |
12 |
| - `g` |
13 |
| - ) |
14 |
| - const allMeetingNotes = core.getInput('rootURLMeetingLogs') |
15 |
| - const sevenDaysAgo: string = new Date(Date.now() - 7 * 24 * 60 * 60 * 1000) |
16 |
| - .toISOString() |
17 |
| - .split('T')[0] |
18 |
| - const meetingNotesURL = allMeetingNotes + sevenDaysAgo + `/` |
19 |
| - const listOfMeetings = await fetchData(meetingNotesURL) |
20 |
| - const matches = listOfMeetings.match(meetingListRegEx) |
21 |
| - |
22 |
| - if (matches != null) { |
23 |
| - const lastMeeting = matches[matches.length - 1] |
24 |
| - // This should be the latest meeting`s date in with the format of YYYY-MM-DD-HH.MM.txt |
25 |
| - const lastMeetingNotesUrl = |
26 |
| - meetingNotesURL + 'fedora-coreos-meeting.' + lastMeeting |
27 |
| - console.debug(`last meeting notes url ${lastMeetingNotesUrl}`) |
28 |
| - const lastMeetingNotes = await fetchData(lastMeetingNotesUrl) |
29 |
| - const actionItemMatches = actionItemsRegEx.exec(lastMeetingNotes) |
30 |
| - |
31 |
| - if (actionItemMatches) { |
32 |
| - console.debug(`action item matches${actionItemMatches[0]}`) |
33 |
| - // if the match is just new lines, then there were no action items |
34 |
| - if (actionItemMatches[0].match(/^\s*$/)) { |
35 |
| - return `!topic there are no action items from the last meeting.` |
| 21 | + console.log('GetActionItems started') |
| 22 | + const listOfAllDateFolders = getAllDateFolders() |
| 23 | + console.log('List of all available dates ', listOfAllDateFolders) |
| 24 | + for (let i = 0; i < listOfAllDateFolders.length; i++) { |
| 25 | + const folder = listOfAllDateFolders[i] |
| 26 | + console.log('Checking folder: ', folder) |
| 27 | + let meetingMatches = await getFCOSMeetingMatches(folder) |
| 28 | + if (meetingMatches != null) { |
| 29 | + console.log('Found FCOS meeting in folder: ', folder) |
| 30 | + // We want the last match, which is just the txt file |
| 31 | + const lastMatch = meetingMatches[meetingMatches.length - 1] |
| 32 | + let meetingTxt = fetchData(`${folder}${lastMatch}`) |
| 33 | + let actionItems = (await meetingTxt).match(actionItemsRegEx) |
| 34 | + if (actionItems != null) { |
| 35 | + console.log('Found action items in meeting notes: ', actionItems[1]) |
| 36 | + // return the the captured group |
| 37 | + return actionItems[1] |
36 | 38 | }
|
37 |
| - return actionItemMatches[0] |
38 | 39 | }
|
39 | 40 | }
|
40 | 41 | } catch (error) {
|
41 | 42 | // Fail the workflow run if an error occurs
|
42 | 43 | if (error instanceof Error) core.setFailed(error.message)
|
43 | 44 | }
|
44 | 45 |
|
45 |
| - return `Failed: to get action items, check the last meeting notes.` |
| 46 | + return 'Failed: to get action items, check the last meeting notes.' |
46 | 47 | }
|
47 | 48 |
|
48 | 49 | async function fetchData(url: string): Promise<string> {
|
49 | 50 | const options = {
|
50 |
| - method: `GET`, |
| 51 | + method: 'GET', |
51 | 52 | url
|
52 | 53 | }
|
53 |
| - return await ( |
54 |
| - await axios(options) |
55 |
| - ).data |
| 54 | + return (await axios(options)).data |
| 55 | +} |
| 56 | + |
| 57 | +function getAllDateFolders(): string[] { |
| 58 | + const urls: string[] = [] |
| 59 | + let match = folderRegex.exec(meetingNotesRootURL) |
| 60 | + if (match == null) { |
| 61 | + throw new Error( |
| 62 | + 'No meetings found in the meeting notes root URL. Check rootURL, or the regex for matching links.' |
| 63 | + ) |
| 64 | + } |
| 65 | + |
| 66 | + for (let i = 0; i < match.length; i++) { |
| 67 | + const folderUrl = match[i] |
| 68 | + const fullUrl = `${meetingNotesRootURL}${folderUrl}/` |
| 69 | + urls.unshift(fullUrl) |
| 70 | + } |
| 71 | + |
| 72 | + return urls |
| 73 | +} |
| 74 | + |
| 75 | +async function getFCOSMeetingMatches( |
| 76 | + html: string |
| 77 | +): Promise<RegExpMatchArray | null> { |
| 78 | + const rawHtml = await fetchData(html) |
| 79 | + const matches = rawHtml.match(meetingListRegEx) |
| 80 | + |
| 81 | + if (matches != null) { |
| 82 | + return matches |
| 83 | + } |
| 84 | + return null |
56 | 85 | }
|
0 commit comments