Skip to content

Commit

Permalink
support repository name and package name being different
Browse files Browse the repository at this point in the history
  • Loading branch information
rohanmars committed May 16, 2024
1 parent 36c606f commit 88727c8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 25 deletions.
30 changes: 18 additions & 12 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32726,6 +32726,7 @@ const github_1 = __nccwpck_require__(5438);
class Config {
owner;
isPrivateRepo = false;
repoName;
name;
tags;
excludeTags;
Expand All @@ -32740,7 +32741,7 @@ class Config {
this.octokit = (0, github_1.getOctokit)(token);
}
async getOwnerType() {
const result = await this.octokit.request(`GET /repos/${this.owner}/${this.name}`);
const result = await this.octokit.request(`GET /repos/${this.owner}/${this.repoName}`);
this.isPrivateRepo = result.data.private;
return result.data.owner.type;
}
Expand All @@ -32750,19 +32751,24 @@ function getConfig() {
const token = core.getInput('token', { required: true });
const config = new Config(token);
// auto populate
if (!config.owner || !config.name) {
const GITHUB_REPOSITORY = process.env['GITHUB_REPOSITORY'];
if (GITHUB_REPOSITORY) {
const parts = GITHUB_REPOSITORY.split('/');
if (parts.length === 2) {
if (!config.owner) {
config.owner = parts[0];
}
if (!config.name) {
config.name = parts[1];
}
const GITHUB_REPOSITORY = process.env['GITHUB_REPOSITORY'];
if (GITHUB_REPOSITORY) {
const parts = GITHUB_REPOSITORY.split('/');
if (parts.length === 2) {
if (!config.owner) {
config.owner = parts[0];
}
if (!config.name) {
config.name = parts[1];
}
config.repoName = parts[1];
}
else {
throw Error(`Error parsing GITHUB_REPOSITORY: ${GITHUB_REPOSITORY}`);
}
}
else {
throw Error('GITHUB_REPOSITORY is not set');
}
config.tags = core.getInput('tags');
config.excludeTags = core.getInput('exclude-tags');
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

28 changes: 16 additions & 12 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { getOctokit } from '@actions/github'
export class Config {
owner?: string
isPrivateRepo = false
repoName?: string
name?: string
tags?: string
excludeTags?: string
Expand All @@ -21,7 +22,7 @@ export class Config {

async getOwnerType(): Promise<string> {
const result = await this.octokit.request(
`GET /repos/${this.owner}/${this.name}`
`GET /repos/${this.owner}/${this.repoName}`
)
this.isPrivateRepo = result.data.private
return result.data.owner.type
Expand All @@ -33,19 +34,22 @@ export function getConfig(): Config {
const config = new Config(token)

// auto populate
if (!config.owner || !config.name) {
const GITHUB_REPOSITORY = process.env['GITHUB_REPOSITORY']
if (GITHUB_REPOSITORY) {
const parts = GITHUB_REPOSITORY.split('/')
if (parts.length === 2) {
if (!config.owner) {
config.owner = parts[0]
}
if (!config.name) {
config.name = parts[1]
}
const GITHUB_REPOSITORY = process.env['GITHUB_REPOSITORY']
if (GITHUB_REPOSITORY) {
const parts = GITHUB_REPOSITORY.split('/')
if (parts.length === 2) {
if (!config.owner) {
config.owner = parts[0]
}
if (!config.name) {
config.name = parts[1]
}
config.repoName = parts[1]
} else {
throw Error(`Error parsing GITHUB_REPOSITORY: ${GITHUB_REPOSITORY}`)
}
} else {
throw Error('GITHUB_REPOSITORY is not set')
}

config.tags = core.getInput('tags')
Expand Down

0 comments on commit 88727c8

Please sign in to comment.