Merge branch 'develop'

This commit is contained in:
Sam Carlton 2020-12-26 12:11:25 -06:00
commit 8b7fbb75b9

View file

@ -42,24 +42,83 @@ const statusesMessages = {
'': '🔶 Unknown, more info needed' '': '🔶 Unknown, more info needed'
} }
function getStatusText(formula) {
class MakeHomebrewList {
constructor() {
// Data from the issue
this.issueTableRowData = null
// Data from the official Homebrew API
this.allFormulaeArray = null
this.allFormulae = null
}
getStatusText (formula) {
// Match status to Sheet Status // Match status to Sheet Status
return statusesMessages[formula.status] return statusesMessages[formula.status]
} }
function parseStatus(formulae) { searchFormulaeForName (name) {
for (const formula of this.allFormulaeArray) {
// Check normal name
if (formula.name === name) return formula
// Check normal oldname
if (formula.oldname === name) return formula
// Check aliases
if ((formula.aliases !== undefined) && formula.aliases.includes(name)) return formula
}
return null
}
formulaIsNative (formulae) {
const formulaData = this.allFormulae[formulae.fullName] || this.searchFormulaeForName(formulae.name)
// If this formula doesn't exist
// then return false
if (formulaData !== Object(formulaData)) {
return false
}
console.log('formulaData', formulaData)
console.log('formulae', formulae)
// Check the official list first since it's data is newer and more frequently updated
const hasStableFormula = (formulaData.bottle.stable !== undefined)
const hasArm64Formula = hasStableFormula && (formulaData.bottle.stable.files['arm64_big_sur'] !== undefined)
return hasArm64Formula
}
parseStatus (formulae) {
// If an ARM 64 formula exists then it's native
if (this.formulaIsNative(formulae)) {
return 'native'
}
// Match status to Sheet Status // Match status to Sheet Status
return statusesTranslations[formulae.status] return statusesTranslations[formulae.status]
} }
async make () {
export default async function () { // Fetch Gihub Issue List
const [
// Fetch Homebrew issueResponse,
const response = await axios.get(process.env.HOMEBREW_SOURCE) allFormulaeResponse
] = await Promise.all([
// Fetch Gihub Issue List
axios.get(process.env.HOMEBREW_SOURCE),
// Fetch Official Homebrew Formulae List
axios.get('https://formulae.brew.sh/api/formula.json')
])
// Extract commit from response data // Extract commit from response data
const issueMarkdown = response.data.data.repository.issue.body const issueMarkdown = issueResponse.data.data.repository.issue.body
// Parse markdown // Parse markdown
const issueHTML = marked(issueMarkdown) const issueHTML = marked(issueMarkdown)
@ -67,6 +126,21 @@ export default async function () {
// Parse Markdown HTML into a dom // Parse Markdown HTML into a dom
const dom = HTMLParser.parse(issueHTML) const dom = HTMLParser.parse(issueHTML)
// Store the original array
this.allFormulaeArray = allFormulaeResponse.data
// Extract list from allFormulaeResponse and map into an object for easy access
this.allFormulae = Object.fromEntries(allFormulaeResponse.data.map(formula => {
return [
formula.full_name,
formula
]
}))
// console.log('allFormulae', allFormulae)
// Map table Headings // Map table Headings
// [ 'Formula', 'Works1on 11.0', 'Comments' ] // [ 'Formula', 'Works1on 11.0', 'Comments' ]
@ -84,7 +158,7 @@ export default async function () {
// Remove the first row (Headings) // Remove the first row (Headings)
tableRows.shift() tableRows.shift()
const tableRowData = tableRows.map( tr => { this.issueTableRowData = tableRows.map( tr => {
// Map Table Cells // Map Table Cells
@ -127,7 +201,7 @@ export default async function () {
const formulaeList = [] const formulaeList = []
for (const formulae of tableRowData) { for (const formulae of this.issueTableRowData) {
// If this formulae status is empty // If this formulae status is empty
// then skip this formulae // then skip this formulae
@ -151,9 +225,9 @@ export default async function () {
formulaeList.push({ formulaeList.push({
name: formulae.name, name: formulae.name,
status: parseStatus(formulae), status: this.parseStatus(formulae),
// url: `https://formulae.brew.sh/formula/${formulae.name}`, // url: `https://formulae.brew.sh/formula/${formulae.name}`,
text: getStatusText(formulae), text: this.getStatusText(formulae),
slug, slug,
endpoint: getAppEndpoint({ endpoint: getAppEndpoint({
slug, slug,
@ -179,3 +253,11 @@ export default async function () {
return formulaeList return formulaeList
} }
}
export default async function () {
const maker = new MakeHomebrewList()
return await maker.make()
}