Skip to content

Commit

Permalink
💅
Browse files Browse the repository at this point in the history
  • Loading branch information
mislav committed Sep 12, 2023
1 parent a26f2e4 commit 02e38c0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
35 changes: 33 additions & 2 deletions src/main-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ test('commitForRelease()', (t) => {
)
})

test('prepareEdit()', async (t) => {
test('prepareEdit() homebrew-core', async (t) => {
const ctx = {
sha: 'TAGSHA',
ref: 'refs/tags/v0.8.2',
Expand All @@ -60,6 +60,7 @@ test('prepareEdit()', async (t) => {
},
}

process.env['GITHUB_REPOSITORY'] = 'monalisa/hello-world'
process.env['INPUT_HOMEBREW-TAP'] = 'Homebrew/homebrew-core'
process.env['INPUT_COMMIT-MESSAGE'] = 'Upgrade {{formulaName}} to {{version}}'

Expand All @@ -85,7 +86,7 @@ test('prepareEdit()', async (t) => {
t.is(opts.owner, 'Homebrew')
t.is(opts.repo, 'homebrew-core')
t.is(opts.branch, '')
t.is(opts.filePath, 'Formula/repo.rb')
t.is(opts.filePath, 'Formula/r/repo.rb')
t.is(opts.commitMessage, 'Upgrade repo to 0.8.2')

const oldFormula = `
Expand All @@ -109,3 +110,33 @@ test('prepareEdit()', async (t) => {
opts.replace(oldFormula)
)
})

test('prepareEdit() non-homebrew-core', async (t) => {
const ctx = {
sha: 'TAGSHA',
ref: 'refs/tags/v0.8.2',
repo: {
owner: 'OWNER',
repo: 'REPO',
},
}

process.env['GITHUB_REPOSITORY'] = 'monalisa/hello-world'
process.env['INPUT_HOMEBREW-TAP'] = 'myorg/homebrew-utils'
process.env['INPUT_COMMIT-MESSAGE'] = 'Upgrade {{formulaName}} to {{version}}'
process.env['INPUT_DOWNLOAD-SHA256'] = 'MOCK-SHA-256'

const apiClient = api('ATOKEN', {
fetch: function (url: string) {
throw url
},
logRequests: false,
})

const opts = await prepareEdit(ctx, apiClient, apiClient)
t.is(opts.owner, 'myorg')
t.is(opts.repo, 'homebrew-utils')
t.is(opts.branch, '')
t.is(opts.filePath, 'Formula/repo.rb')
t.is(opts.commitMessage, 'Upgrade repo to 0.8.2')
})
14 changes: 13 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ function tarballForRelease(
return `https://github.com/${owner}/${repo}/archive/${tagName}.tar.gz`
}

function formulaPath(owner: string, repo: string, formulaName: string): string {
if (
owner.toLowerCase() == 'homebrew' &&
repo.toLowerCase() == 'homebrew-core'
) {
// respect formula sharding structure in `Homebrew/homebrew-core`
return `Formula/${formulaName.charAt(0)}/${formulaName}.rb`
}
return `Formula/${formulaName}.rb`
}

export function commitForRelease(
messageTemplate: string,
params: { [key: string]: string } = {}
Expand Down Expand Up @@ -82,7 +93,8 @@ export async function prepareEdit(
}
const formulaName = getInput('formula-name') || ctx.repo.repo.toLowerCase()
const branch = getInput('base-branch')
const filePath = getInput('formula-path') || `Formula/${formulaName.charAt(0)}/${formulaName}.rb`
const filePath =
getInput('formula-path') || formulaPath(owner, repo, formulaName)
const version = tagName.replace(/^v(\d)/, '$1')
const downloadUrl =
getInput('download-url') ||
Expand Down

0 comments on commit 02e38c0

Please sign in to comment.