-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: cherry init template should explicitly set up repository info (#145
) * improve init * remove test * improve logs and export default * inline templates * remove deps * refactor
- Loading branch information
Showing
10 changed files
with
70 additions
and
214 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import path from 'path' | ||
import { PermalinkFn, Repository } from './types.js' | ||
import { Host, PermalinkFn, Repository } from './types.js' | ||
|
||
export const buildRepoURL = (repository: Repository) => | ||
`https://${repository.host}/${repository.owner}/${repository.name}` | ||
|
@@ -34,15 +34,15 @@ export async function guessRepositoryInfo({ | |
remoteUrl: string | null | ||
configFile: string | null | ||
projectRoot: string | ||
}) { | ||
}): Promise<Repository> { | ||
if (remoteUrl === null) { | ||
throw new Error('Could not guess repository info: no remote URL found') | ||
} | ||
|
||
// For github ssh remotes such as git@github.com:cherrypush/cherry-cli.git | ||
if (remoteUrl.includes('[email protected]')) { | ||
return { | ||
host: 'github.com', | ||
host: Host.Github, | ||
owner: remoteUrl.split(':')[1].split('/')[0], | ||
name: remoteUrl.split('/')[1].replace('.git', ''), | ||
subdir: guessRepositorySubdir({ configFile, projectRoot }), | ||
|
@@ -52,7 +52,7 @@ export async function guessRepositoryInfo({ | |
// For github https remotes such as https://github.com/cherrypush/cherry-cli.git | ||
if (remoteUrl.includes('https://github.com')) { | ||
return { | ||
host: 'github.com', | ||
host: Host.Github, | ||
owner: remoteUrl.split('/')[3], | ||
name: remoteUrl.split('/')[4].replace('.git', ''), | ||
subdir: guessRepositorySubdir({ configFile, projectRoot }), | ||
|
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,47 @@ | ||
import { Repository } from './types.js' | ||
|
||
export function getConfigTemplate(repositoryInfo: Repository) { | ||
return `// For detailed configuration options, see the documentation: | ||
// https://www.cherrypush.com/docs | ||
// | ||
// In this configuration file, you can set up your repository information, | ||
// enable plugins, and define custom metrics for your codebase. | ||
export default { | ||
repository: { | ||
host: '${repositoryInfo.host}', | ||
owner: '${repositoryInfo.owner}', | ||
name: '${repositoryInfo.name}', | ||
subdir: '${repositoryInfo.subdir}', | ||
}, | ||
plugins: { loc: {} }, | ||
metrics: [ | ||
{ | ||
name: 'TODO/FIXME', | ||
pattern: /(TODO|FIXME):/i, | ||
}, | ||
], | ||
}` | ||
} | ||
|
||
export function getWorkflowTemplate() { | ||
return `name: cherry push | ||
on: | ||
push: | ||
branches: | ||
- \${{ github.event.repository.default_branch }} | ||
jobs: | ||
cherry_push: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout project | ||
uses: actions/checkout@v4 | ||
- name: Install dependencies | ||
run: npm i -g cherrypush | ||
- name: Push metrics to Cherry | ||
run: cherry push --quiet --api-key=\${{ secrets.CHERRY_API_KEY }}` | ||
} |
Oops, something went wrong.