Skip to content

Commit

Permalink
feat: retain the ability to override the hostname
Browse files Browse the repository at this point in the history
  • Loading branch information
ianwremmel committed Apr 19, 2022
1 parent cfae3c5 commit 38dcf7f
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 14 deletions.
1 change: 0 additions & 1 deletion integrations/action/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ branding:
color: 'orange'
inputs:
hostname:
default: api.check-run-reporter.com
description: Internal. Do not use unless directed. Supercedes --url
required: false
label:
Expand Down
3 changes: 2 additions & 1 deletion integrations/action/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,10 @@ async function main() {
core.getInput('label') ||
`${github.context.workflow} / ${github.context.job}`;

const hostname = core.getInput('hostname');
const token = core.getInput('token');

const client = makeClient();
const client = makeClient({hostname});

const tests = core.getInput('tests');
if (tests) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ log () {
echo "$@" 1>&2
}

HOSTNAME=${BUILDKITE_PLUGIN_CHECK_RUN_REPORTER_HOSTNAME:-api.check-run-reporter.com}
HOSTNAME=${BUILDKITE_PLUGIN_CHECK_RUN_REPORTER_HOSTNAME:-''}
LABEL=${BUILDKITE_PLUGIN_CHECK_RUN_REPORTER_LABEL:-$BUILDKITE_LABEL}
ROOT=${BUILDKITE_PLUGIN_CHECK_RUN_REPORTER_ROOT:-$(find_root)}
SHA=$BUILDKITE_COMMIT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ log () {
echo "$@" 1>&2
}

HOSTNAME=${BUILDKITE_PLUGIN_CHECK_RUN_REPORTER_HOSTNAME:-api.check-run-reporter.com}
HOSTNAME=${BUILDKITE_PLUGIN_CHECK_RUN_REPORTER_HOSTNAME:-''}
LABEL=${BUILDKITE_PLUGIN_CHECK_RUN_REPORTER_LABEL:-$BUILDKITE_LABEL}
TOKEN=$BUILDKITE_PLUGIN_CHECK_RUN_REPORTER_TOKEN
TESTS=${BUILDKITE_PLUGIN_CHECK_RUN_REPORTER_TESTS:-''}
Expand Down
12 changes: 6 additions & 6 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export function cli(argv: string[]) {
(y) =>
y.options({
hostname: {
default: 'api.check-run-reporter.com',
description: 'Internal. Do not use unless directed.',
type: 'string',
},
json: {
default: false,
Expand Down Expand Up @@ -54,14 +54,14 @@ export function cli(argv: string[]) {
type: 'string',
},
}),
async ({tests, ...args}) => {
async ({hostname, tests, ...args}) => {
const directlyUseOutput = !process.stdout.isTTY;

try {
const result = await split(
{...args, tests: tests.map(String)},
{
client: makeClient(),
client: makeClient({hostname}),
logger: directlyUseOutput ? silentLogger : logger,
}
);
Expand Down Expand Up @@ -94,8 +94,8 @@ export function cli(argv: string[]) {
(y) =>
y.options({
hostname: {
default: 'api.check-run-reporter.com',
description: 'Internal. Do not use unless directed.',
type: 'string',
},
label: {
description: 'Label that should appear in the GitHub check run.',
Expand Down Expand Up @@ -125,13 +125,13 @@ export function cli(argv: string[]) {
type: 'string',
},
}),
async ({report, ...args}) => {
async ({hostname, report, ...args}) => {
return submit(
{
...args,
report: report.map(String),
},
{client: makeClient(), logger}
{client: makeClient({hostname}), logger}
);
}
)
Expand Down
8 changes: 5 additions & 3 deletions src/lib/axios.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'axios-debug-log';

import axiosRetry from 'axios-retry';
import axios, {AxiosResponse} from 'axios';
import axios, {AxiosInstance, AxiosResponse} from 'axios';
import ci from 'ci-info';

import pkg from '../../package.json';
Expand All @@ -12,9 +12,11 @@ const {version} = pkg;
/**
* Creates a new http client with configuration
*/
export function makeClient() {
export function makeClient({hostname}: {hostname?: string}): AxiosInstance {
// Do not use ?? here in case hostname is an empty string
hostname = hostname || HOSTNAME;
const client = axios.create({
baseURL: new URL(BASEPATH, `https://${HOSTNAME}`).toString(),
baseURL: new URL(BASEPATH, `https://${hostname}`).toString(),
headers: {
'user-agent': [
`crr/${version}`,
Expand Down
2 changes: 1 addition & 1 deletion src/test/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ import {Context} from '../lib/types';
* Creates a (semi) mocked context for use in tests.
*/
export function makeTestContext(): Context {
return {client: makeClient(), logger: console};
return {client: makeClient({}), logger: console};
}

0 comments on commit 38dcf7f

Please sign in to comment.