Skip to content

Commit

Permalink
feat: ✨ allow 2 repo inputs: source and destination
Browse files Browse the repository at this point in the history
  • Loading branch information
meisZWFLZ authored Feb 3, 2024
1 parent edb8d47 commit 43f29d0
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 14 deletions.
13 changes: 12 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,18 @@ branding:
# Define your inputs here.
inputs:
repo:
description: 'The string represetation of the repo name (eg: lemlib/lemlib)'
description: |
Repository to which the depot will be pushed to.
If source-repo is not defined, then this parameter will be assumed to be the source repo.
If left undefined, then this parameter will be inferred from the workflow that called this action.
example: "lemlib/lemlib"
required: false

source-repo:
description: |
Repository from which to retrieve releases from
If left undefined, then the repo parameter will be assumed to be the source repo.
example: "lemlib/lemlib"
required: false

token:
Expand Down
17 changes: 11 additions & 6 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions dist/licenses.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 15 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ import { updateDepots } from './update'

const repoInputRegex = /[^\/\n\s\t]+\/[^\/\n\s\t]+/

Check failure on line 6 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Unnecessary escape character: \/

Check failure on line 6 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Unnecessary escape character: \/

function getRepositoryIdentifier(): RepositoryIdentifier {
function getRepositoryIdentifier(repoInput: string): RepositoryIdentifier {
const repo: { owner: string; repo: string } = github.context.repo
const repoInput = core.getInput('repo')

core.info('Repository input: ' + repoInput)

if (repoInput.match(repoInputRegex)) {
const parsedRepoInput = repoInput.split('/')
Expand All @@ -18,6 +15,18 @@ function getRepositoryIdentifier(): RepositoryIdentifier {
} else throw new Error('Invalid repository input: ' + repoInput)

Check failure on line 15 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Unexpected string concatenation
return repo
}
function getRepositoryIdentifiers(): Record<
'srcRepo' | 'destRepo',
RepositoryIdentifier
> {
const destInput = core.getInput('repo')
let srcInput = core.getInput('source-repo')
srcInput ??= destInput

const srcRepo = getRepositoryIdentifier(srcInput)
const destRepo = getRepositoryIdentifier(destInput)
return { srcRepo, destRepo }
}

function getDepotLocations(): DepotRouteMap {
const stableBranch = core.getInput('branch')
Expand All @@ -43,16 +52,15 @@ function getDepotLocations(): DepotRouteMap {
*/
export async function run(): Promise<void> {
try {
const repo = getRepositoryIdentifier()
const repos = getRepositoryIdentifiers()
const routes = getDepotLocations()

const readableFlag = core.getInput('readable') === 'true'
const ghToken = core.getInput('token')
const message = core.getInput('message')

updateDepots({
destRepo: repo,
srcRepo: repo,
...repos,
routes,
readableJson: readableFlag,
token: ghToken,
Expand Down

0 comments on commit 43f29d0

Please sign in to comment.