-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
11 changed files
with
73 additions
and
68 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,8 +10,6 @@ on: | |
push: | ||
branches: | ||
- main | ||
- latest | ||
- release/v* | ||
paths: | ||
- workspace/test-workspace/** | ||
schedule: | ||
|
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 |
---|---|---|
|
@@ -11,8 +11,6 @@ on: | |
push: | ||
branches: | ||
- main | ||
- latest | ||
- release/v* | ||
|
||
permissions: | ||
contents: write | ||
|
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 |
---|---|---|
|
@@ -8,7 +8,7 @@ on: | |
type: string | ||
push: | ||
branches: | ||
{{#each branches}} | ||
{{#each branchPatterns}} | ||
- {{ . }} | ||
{{/each}} | ||
|
||
|
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,63 @@ | ||
const hgi = require('hosted-git-info') | ||
const git = require('@npmcli/git') | ||
const { minimatch } = require('minimatch') | ||
|
||
const cache = new Map() | ||
|
||
const tryGit = async (path, ...args) => { | ||
if (!await git.is({ cwd: path })) { | ||
throw new Error('no git') | ||
} | ||
const key = [path, ...args].join(',') | ||
if (cache.has(key)) { | ||
return cache.get(key) | ||
} | ||
const res = git.spawn(args, { cwd: path }).then(r => r.stdout.trim()) | ||
cache.set(key, res) | ||
return res | ||
} | ||
|
||
// parse a repo from a git origin into a format | ||
// for a package.json#repository object | ||
const getUrl = async (path) => { | ||
try { | ||
const urlStr = await tryGit(path, 'remote', 'get-url', 'origin') | ||
const { domain, user, project } = hgi.fromUrl(urlStr) | ||
const url = new URL(`https://${domain}`) | ||
url.pathname = `/${user}/${project}.git` | ||
return url.toString() | ||
} catch { | ||
// errors are ignored | ||
} | ||
} | ||
|
||
const getBranches = async (path, branchPatterns) => { | ||
let matchingBranches = new Set() | ||
let matchingPatterns = new Set() | ||
|
||
try { | ||
const res = await tryGit(path, 'ls-remote', '--heads', 'origin').then(r => r.split('\n')) | ||
const remotes = res.map((h) => h.match(/refs\/heads\/(.*)$/)).filter(Boolean).map(h => h[1]) | ||
for (const branch of remotes) { | ||
for (const pattern of branchPatterns) { | ||
if (minimatch(branch, pattern)) { | ||
matchingBranches.add(branch) | ||
matchingPatterns.add(pattern) | ||
} | ||
} | ||
} | ||
} catch { | ||
matchingBranches = new Set() | ||
matchingPatterns = new Set(branchPatterns) | ||
} | ||
|
||
return { | ||
branches: [...matchingBranches], | ||
patterns: [...matchingPatterns], | ||
} | ||
} | ||
|
||
module.exports = { | ||
getUrl, | ||
getBranches, | ||
} |