Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add input for the config repository #131

Merged
merged 4 commits into from
Apr 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ jobs:
with:
github-token: ${{secrets.GITHUB_TOKEN}} # optional, default to '${{ github.token }}'
config-path: .github/labeler.yml # optional, default to '.github/labeler.yml'
config-repo: my-org/my-repo # optional, default to '${{ github.repository }}'
```

#### `.github/labeler.yml`
Expand Down Expand Up @@ -288,7 +289,10 @@ labels:
## Configuration

Once you’ve added multi-labeler to your repository, it must be enabled by adding a `.github/labeler.yml` configuration
file to the repository.
file to the repository. If you want to use a configuration file shared across multiple repositories, you can set the
`config-repo` input to point to a different repository. However, make sure to set a `github-token` that has permissions
to access the provided repository, as the default `GITHUB_TOKEN` only has access to the repository the action is
running in.

## Matchers

Expand Down
2 changes: 1 addition & 1 deletion __tests__/checks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async function runChecks(
configPath: string,
labels: string[]
): Promise<StatusCheck[]> {
const config = await getConfig(client, configPath)
const config = await getConfig(client, configPath, 'owner-name/repo-name')
return checks(client, config, labels)
}

Expand Down
2 changes: 1 addition & 1 deletion __tests__/labeler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const client: InstanceType<typeof GitHub> = {
}

async function runLabels(configPath: string): Promise<string[]> {
const config = await getConfig(client, configPath)
const config = await getConfig(client, configPath, 'owner-name/repo-name')
return labels(client, config)
}

Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ inputs:
description: 'The path for the label configurations'
default: '.github/labeler.yml'
required: false
config-repo:
description: 'The repository for the label configurations'
default: ${{ github.repository }}
required: false
github-token:
description: 'GITHUB_TOKEN or a `repo` scoped Personal Access Token (PAT)'
required: false
Expand Down
15 changes: 10 additions & 5 deletions dist/index.js

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

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

13 changes: 9 additions & 4 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,17 @@ export function parse(content: string): Config {

export async function getConfig(
client: InstanceType<typeof GitHub>,
configPath: string
configPath: string,
configRepo: string
): Promise<Config> {
const [owner, repo] = configRepo.split('/')
const response: any = await client.repos.getContent({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
ref: github.context.sha,
owner,
repo,
ref:
configRepo === github.context.payload.repository?.full_name
? github.context.sha
: undefined,
path: configPath
})

Expand Down
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {checks, StatusCheck} from './checks'

const githubToken = core.getInput('github-token')
const configPath = core.getInput('config-path', {required: true})
const configRepo = core.getInput('config-repo')

const client = github.getOctokit(githubToken)
const payload =
Expand Down Expand Up @@ -87,7 +88,7 @@ async function addChecks(checks: StatusCheck[]): Promise<void> {
])
}

getConfig(client, configPath)
getConfig(client, configPath, configRepo)
.then(async config => {
const labeled = await labels(client, config)
const finalLabels = mergeLabels(labeled, config)
Expand Down