-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
196 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import test from 'ava' | ||
import api from './api' | ||
import { commitForRelease, prepareEdit } from './main' | ||
import { Response } from 'node-fetch' | ||
|
||
test('commitForRelease()', (t) => { | ||
t.is( | ||
commitForRelease('This is a fixed commit message', { | ||
formulaName: 'test formula', | ||
}), | ||
'This is a fixed commit message' | ||
) | ||
t.is( | ||
commitForRelease('chore({{formulaName}}): version {{version}}', { | ||
formulaName: 'test formula', | ||
}), | ||
'chore(test formula): version {{version}}' | ||
) | ||
t.is( | ||
commitForRelease('chore({{formulaName}}): upgrade to version {{version}}', { | ||
formulaName: 'test formula', | ||
version: 'v1.2.3', | ||
}), | ||
'chore(test formula): upgrade to version v1.2.3' | ||
) | ||
}) | ||
|
||
test('prepareEdit()', async (t) => { | ||
const ctx = { | ||
sha: 'TAGSHA', | ||
ref: 'refs/tags/v0.8.2', | ||
repo: { | ||
owner: 'OWNER', | ||
repo: 'REPO', | ||
}, | ||
} | ||
|
||
process.env['INPUT_HOMEBREW-TAP'] = 'Homebrew/homebrew-core' | ||
process.env['INPUT_COMMIT-MESSAGE'] = 'Upgrade {{formulaName}} to {{version}}' | ||
|
||
// FIXME: this tests results in a live HTTP request. Figure out how to stub the `stream()` method in | ||
// calculate-download-checksum. | ||
const stubbedFetch = function (url: string) { | ||
if (url == 'https://api.github.com/repos/OWNER/REPO/tarball/v0.8.2') { | ||
return Promise.resolve( | ||
new Response('', { | ||
status: 301, | ||
headers: { | ||
Location: | ||
'https://github.com/mislav/bump-homebrew-formula-action/archive/v1.9.tar.gz', | ||
}, | ||
}) | ||
) | ||
} | ||
throw url | ||
} | ||
const apiClient = api('ATOKEN', { fetch: stubbedFetch }) | ||
|
||
const opts = await prepareEdit(ctx, apiClient, apiClient) | ||
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.commitMessage, 'Upgrade repo to 0.8.2') | ||
|
||
const oldFormula = ` | ||
class MyProgram < Formula | ||
url "OLDURL" | ||
sha256 "OLDSHA" | ||
end | ||
` | ||
t.is( | ||
opts.replace(oldFormula), | ||
` | ||
class MyProgram < Formula | ||
url "https://github.com/OWNER/REPO/archive/v0.8.2.tar.gz" | ||
sha256 "c036fbc44901b266f6d408d6ca36ba56f63c14cc97994a935fb9741b55edee83" | ||
end | ||
` | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import test from 'ava' | ||
import { replaceFields } from './replace-formula-fields' | ||
|
||
test('replaceFields()', (t) => { | ||
const input = ` | ||
url "https://github.com/old/url.git", | ||
tag: 'v0.9.0', | ||
revision => "OLDREV" | ||
` | ||
const expected = ` | ||
url "https://github.com/cli/cli.git", | ||
tag: 'v0.11.1', | ||
revision => "NEWREV" | ||
` | ||
|
||
const replacements = new Map<string, string>() | ||
replacements.set('url', 'https://github.com/cli/cli.git') | ||
replacements.set('tag', 'v0.11.1') | ||
replacements.set('revision', 'NEWREV') | ||
|
||
t.is(replaceFields(input, replacements), expected) | ||
}) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import test from 'ava' | ||
import { fromUrl } from './version' | ||
|
||
test('fromUrl()', (t) => { | ||
t.is( | ||
fromUrl('https://github.com/me/myproject/archive/v1.2.3.tar.gz'), | ||
'v1.2.3' | ||
) | ||
t.is( | ||
fromUrl( | ||
'https://github.com/me/myproject/releases/download/v1.2.3/file.tgz' | ||
), | ||
'v1.2.3' | ||
) | ||
t.is(fromUrl('http://myproject.net/download/v1.2.3.tgz'), 'v1.2.3') | ||
t.is(fromUrl('https://example.com/v1.2.3.zip'), 'v1.2.3') | ||
}) |