-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
With the latest change, we had to introduce a very fragile concept. Where we looked 7 days prior to capture the last weeks meeting. Instead remove this, and iterate through each folder to capture the last meeting. More work but should reduce fragileness. Additonally action items were not being correctly matched. Update regex for actionItems. fixes: coreos#50
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,85 @@ | ||
import * as core from '@actions/core' | ||
import { match } from 'assert' | ||
import axios from 'axios' | ||
|
||
const actionItemsRegEx = new RegExp( | ||
`Action items\n[-]+\n([\s\S]*?)\nPeople Present`, | ||
Check failure on line 6 in src/actionItems.ts GitHub Actions / Lint Code Base
|
||
'm' | ||
) | ||
const meetingListRegEx = new RegExp( | ||
`(?<=>fedora-coreos-meeting.)(.*?)=?txt`, | ||
`g` | ||
) | ||
const folderRegex = new RegExp( | ||
`/<img src="\/icons\/folder.gif" alt="\[DIR\]"> <a href="([^"]+)\/">/`, | ||
Check failure on line 14 in src/actionItems.ts GitHub Actions / Lint Code Base
Check failure on line 14 in src/actionItems.ts GitHub Actions / Lint Code Base
Check failure on line 14 in src/actionItems.ts GitHub Actions / Lint Code Base
Check failure on line 14 in src/actionItems.ts GitHub Actions / Lint Code Base
|
||
`g` | ||
) | ||
const meetingNotesRootURL = core.getInput('rootURLMeetingLogs') | ||
|
||
export async function GetActionItems(): Promise<string> { | ||
try { | ||
console.log(`GetActionItems started`) | ||
// Set constants | ||
const actionItemsRegEx = new RegExp( | ||
`(?<=Action Items\n------------\n)((.|\n)*)(?=Action Items,)` | ||
) | ||
const meetingListRegEx = new RegExp( | ||
`(?<=>fedora-coreos-meeting.)(.*?)=?txt`, | ||
`g` | ||
) | ||
const allMeetingNotes = core.getInput('rootURLMeetingLogs') | ||
const sevenDaysAgo: string = new Date(Date.now() - 7 * 24 * 60 * 60 * 1000) | ||
.toISOString() | ||
.split('T')[0] | ||
const meetingNotesURL = allMeetingNotes + sevenDaysAgo + `/` | ||
const listOfMeetings = await fetchData(meetingNotesURL) | ||
const matches = listOfMeetings.match(meetingListRegEx) | ||
|
||
if (matches != null) { | ||
const lastMeeting = matches[matches.length - 1] | ||
// This should be the latest meeting`s date in with the format of YYYY-MM-DD-HH.MM.txt | ||
const lastMeetingNotesUrl = | ||
meetingNotesURL + 'fedora-coreos-meeting.' + lastMeeting | ||
console.debug(`last meeting notes url ${lastMeetingNotesUrl}`) | ||
const lastMeetingNotes = await fetchData(lastMeetingNotesUrl) | ||
const actionItemMatches = actionItemsRegEx.exec(lastMeetingNotes) | ||
|
||
if (actionItemMatches) { | ||
console.debug(`action item matches${actionItemMatches[0]}`) | ||
// if the match is just new lines, then there were no action items | ||
if (actionItemMatches[0].match(/^\s*$/)) { | ||
return `!topic there are no action items from the last meeting.` | ||
console.log('GetActionItems started') | ||
const listOfAllDateFolders = getAllDateFolders() | ||
console.log('List of all available dates ', listOfAllDateFolders) | ||
for (let i = 0; i < listOfAllDateFolders.length; i++) { | ||
const folder = listOfAllDateFolders[i] | ||
console.log('Checking folder: ', folder) | ||
let meetingMatches = await getFCOSMeetingMatches(folder) | ||
if (meetingMatches != null) { | ||
console.log('Found FCOS meeting in folder: ', folder) | ||
// We want the last match, which is just the txt file | ||
const lastMatch = meetingMatches[meetingMatches.length - 1] | ||
let meetingTxt = fetchData(`${folder}${lastMatch}`) | ||
let actionItems = (await meetingTxt).match(actionItemsRegEx) | ||
if (actionItems != null) { | ||
console.log('Found action items in meeting notes: ', actionItems[1]) | ||
// return the the captured group | ||
return actionItems[1] | ||
} | ||
return actionItemMatches[0] | ||
} | ||
} | ||
} catch (error) { | ||
// Fail the workflow run if an error occurs | ||
if (error instanceof Error) core.setFailed(error.message) | ||
} | ||
|
||
return `Failed: to get action items, check the last meeting notes.` | ||
return 'Failed: to get action items, check the last meeting notes.' | ||
} | ||
|
||
async function fetchData(url: string): Promise<string> { | ||
const options = { | ||
method: `GET`, | ||
method: 'GET', | ||
url | ||
} | ||
return await ( | ||
await axios(options) | ||
).data | ||
return (await axios(options)).data | ||
} | ||
|
||
function getAllDateFolders(): string[] { | ||
const urls: string[] = [] | ||
let match = folderRegex.exec(meetingNotesRootURL) | ||
if (match == null) { | ||
throw new Error( | ||
'No meetings found in the meeting notes root URL. Check rootURL, or the regex for matching links.' | ||
) | ||
} | ||
|
||
for (let i = 0; i < match.length; i++) { | ||
const folderUrl = match[i] | ||
const fullUrl = `${meetingNotesRootURL}${folderUrl}/` | ||
urls.unshift(fullUrl) | ||
} | ||
|
||
return urls | ||
} | ||
|
||
async function getFCOSMeetingMatches( | ||
html: string | ||
): Promise<RegExpMatchArray | null> { | ||
const rawHtml = await fetchData(html) | ||
const matches = rawHtml.match(meetingListRegEx) | ||
|
||
if (matches != null) { | ||
return matches | ||
} | ||
return null | ||
} |