Skip to content

Commit 85b1f35

Browse files
authored
changes to support ghes alpha release (#199)
1 parent 574281d commit 85b1f35

File tree

5 files changed

+93
-24
lines changed

5 files changed

+93
-24
lines changed

dist/index.js

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,6 +1266,46 @@ const windowsRelease = release => {
12661266
module.exports = windowsRelease;
12671267

12681268

1269+
/***/ }),
1270+
1271+
/***/ 81:
1272+
/***/ (function(__unusedmodule, exports, __webpack_require__) {
1273+
1274+
"use strict";
1275+
1276+
var __importStar = (this && this.__importStar) || function (mod) {
1277+
if (mod && mod.__esModule) return mod;
1278+
var result = {};
1279+
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
1280+
result["default"] = mod;
1281+
return result;
1282+
};
1283+
Object.defineProperty(exports, "__esModule", { value: true });
1284+
const assert = __importStar(__webpack_require__(357));
1285+
const url_1 = __webpack_require__(835);
1286+
function getApiUrl() {
1287+
return process.env['GITHUB_API_URL'] || 'https://api.github.com';
1288+
}
1289+
exports.getApiUrl = getApiUrl;
1290+
function getFetchUrl(settings) {
1291+
assert.ok(settings.repositoryOwner, 'settings.repositoryOwner must be defined');
1292+
assert.ok(settings.repositoryName, 'settings.repositoryName must be defined');
1293+
const serviceUrl = getServerUrl();
1294+
const encodedOwner = encodeURIComponent(settings.repositoryOwner);
1295+
const encodedName = encodeURIComponent(settings.repositoryName);
1296+
if (settings.sshKey) {
1297+
return `git@${serviceUrl.hostname}:${encodedOwner}/${encodedName}.git`;
1298+
}
1299+
// "origin" is SCHEME://HOSTNAME[:PORT]
1300+
return `${serviceUrl.origin}/${encodedOwner}/${encodedName}`;
1301+
}
1302+
exports.getFetchUrl = getFetchUrl;
1303+
function getServerUrl() {
1304+
return new url_1.URL(process.env['GITHUB_URL'] || 'https://github.com');
1305+
}
1306+
exports.getServerUrl = getServerUrl;
1307+
1308+
12691309
/***/ }),
12701310

12711311
/***/ 87:
@@ -5109,30 +5149,32 @@ const os = __importStar(__webpack_require__(87));
51095149
const path = __importStar(__webpack_require__(622));
51105150
const regexpHelper = __importStar(__webpack_require__(528));
51115151
const stateHelper = __importStar(__webpack_require__(153));
5152+
const urlHelper = __importStar(__webpack_require__(81));
51125153
const v4_1 = __importDefault(__webpack_require__(826));
51135154
const IS_WINDOWS = process.platform === 'win32';
5114-
const HOSTNAME = 'github.com';
51155155
const SSH_COMMAND_KEY = 'core.sshCommand';
51165156
function createAuthHelper(git, settings) {
51175157
return new GitAuthHelper(git, settings);
51185158
}
51195159
exports.createAuthHelper = createAuthHelper;
51205160
class GitAuthHelper {
51215161
constructor(gitCommandManager, gitSourceSettings) {
5122-
this.tokenConfigKey = `http.https://${HOSTNAME}/.extraheader`;
5123-
this.insteadOfKey = `url.https://${HOSTNAME}/.insteadOf`;
5124-
this.insteadOfValue = `git@${HOSTNAME}:`;
51255162
this.sshCommand = '';
51265163
this.sshKeyPath = '';
51275164
this.sshKnownHostsPath = '';
51285165
this.temporaryHomePath = '';
51295166
this.git = gitCommandManager;
51305167
this.settings = gitSourceSettings || {};
51315168
// Token auth header
5169+
const serverUrl = urlHelper.getServerUrl();
5170+
this.tokenConfigKey = `http.${serverUrl.origin}/.extraheader`; // "origin" is SCHEME://HOSTNAME[:PORT]
51325171
const basicCredential = Buffer.from(`x-access-token:${this.settings.authToken}`, 'utf8').toString('base64');
51335172
core.setSecret(basicCredential);
51345173
this.tokenPlaceholderConfigValue = `AUTHORIZATION: basic ***`;
51355174
this.tokenConfigValue = `AUTHORIZATION: basic ${basicCredential}`;
5175+
// Instead of SSH URL
5176+
this.insteadOfKey = `url.${serverUrl.origin}/.insteadOf`; // "origin" is SCHEME://HOSTNAME[:PORT]
5177+
this.insteadOfValue = `git@${serverUrl.hostname}:`;
51365178
}
51375179
configureAuth() {
51385180
return __awaiter(this, void 0, void 0, function* () {
@@ -5797,14 +5839,12 @@ const io = __importStar(__webpack_require__(1));
57975839
const path = __importStar(__webpack_require__(622));
57985840
const refHelper = __importStar(__webpack_require__(227));
57995841
const stateHelper = __importStar(__webpack_require__(153));
5800-
const hostname = 'github.com';
5842+
const urlHelper = __importStar(__webpack_require__(81));
58015843
function getSource(settings) {
58025844
return __awaiter(this, void 0, void 0, function* () {
58035845
// Repository URL
58045846
core.info(`Syncing repository: ${settings.repositoryOwner}/${settings.repositoryName}`);
5805-
const repositoryUrl = settings.sshKey
5806-
? `git@${hostname}:${encodeURIComponent(settings.repositoryOwner)}/${encodeURIComponent(settings.repositoryName)}.git`
5807-
: `https://${hostname}/${encodeURIComponent(settings.repositoryOwner)}/${encodeURIComponent(settings.repositoryName)}`;
5847+
const repositoryUrl = urlHelper.getFetchUrl(settings);
58085848
// Remove conflicting file path
58095849
if (fsHelper.fileExistsSync(settings.repositoryPath)) {
58105850
yield io.rmRF(settings.repositoryPath);
@@ -9159,6 +9199,7 @@ const io = __importStar(__webpack_require__(1));
91599199
const path = __importStar(__webpack_require__(622));
91609200
const retryHelper = __importStar(__webpack_require__(587));
91619201
const toolCache = __importStar(__webpack_require__(533));
9202+
const urlHelper = __importStar(__webpack_require__(81));
91629203
const v4_1 = __importDefault(__webpack_require__(826));
91639204
const IS_WINDOWS = process.platform === 'win32';
91649205
function downloadRepository(authToken, owner, repo, ref, commit, repositoryPath) {
@@ -9209,7 +9250,7 @@ function downloadRepository(authToken, owner, repo, ref, commit, repositoryPath)
92099250
exports.downloadRepository = downloadRepository;
92109251
function downloadArchive(authToken, owner, repo, ref, commit) {
92119252
return __awaiter(this, void 0, void 0, function* () {
9212-
const octokit = new github.GitHub(authToken);
9253+
const octokit = new github.GitHub(authToken, { baseUrl: urlHelper.getApiUrl() });
92139254
const params = {
92149255
owner: owner,
92159256
repo: repo,

src/git-auth-helper.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import * as os from 'os'
77
import * as path from 'path'
88
import * as regexpHelper from './regexp-helper'
99
import * as stateHelper from './state-helper'
10+
import * as urlHelper from './url-helper'
1011
import {default as uuid} from 'uuid/v4'
1112
import {IGitCommandManager} from './git-command-manager'
1213
import {IGitSourceSettings} from './git-source-settings'
1314

1415
const IS_WINDOWS = process.platform === 'win32'
15-
const HOSTNAME = 'github.com'
1616
const SSH_COMMAND_KEY = 'core.sshCommand'
1717

1818
export interface IGitAuthHelper {
@@ -33,15 +33,15 @@ export function createAuthHelper(
3333
class GitAuthHelper {
3434
private readonly git: IGitCommandManager
3535
private readonly settings: IGitSourceSettings
36-
private readonly tokenConfigKey: string = `http.https://${HOSTNAME}/.extraheader`
36+
private readonly tokenConfigKey: string
37+
private readonly tokenConfigValue: string
3738
private readonly tokenPlaceholderConfigValue: string
38-
private readonly insteadOfKey: string = `url.https://${HOSTNAME}/.insteadOf`
39-
private readonly insteadOfValue: string = `git@${HOSTNAME}:`
39+
private readonly insteadOfKey: string
40+
private readonly insteadOfValue: string
4041
private sshCommand = ''
4142
private sshKeyPath = ''
4243
private sshKnownHostsPath = ''
4344
private temporaryHomePath = ''
44-
private tokenConfigValue: string
4545

4646
constructor(
4747
gitCommandManager: IGitCommandManager,
@@ -51,13 +51,19 @@ class GitAuthHelper {
5151
this.settings = gitSourceSettings || (({} as unknown) as IGitSourceSettings)
5252

5353
// Token auth header
54+
const serverUrl = urlHelper.getServerUrl()
55+
this.tokenConfigKey = `http.${serverUrl.origin}/.extraheader` // "origin" is SCHEME://HOSTNAME[:PORT]
5456
const basicCredential = Buffer.from(
5557
`x-access-token:${this.settings.authToken}`,
5658
'utf8'
5759
).toString('base64')
5860
core.setSecret(basicCredential)
5961
this.tokenPlaceholderConfigValue = `AUTHORIZATION: basic ***`
6062
this.tokenConfigValue = `AUTHORIZATION: basic ${basicCredential}`
63+
64+
// Instead of SSH URL
65+
this.insteadOfKey = `url.${serverUrl.origin}/.insteadOf` // "origin" is SCHEME://HOSTNAME[:PORT]
66+
this.insteadOfValue = `git@${serverUrl.hostname}:`
6167
}
6268

6369
async configureAuth(): Promise<void> {

src/git-source-provider.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,16 @@ import * as io from '@actions/io'
88
import * as path from 'path'
99
import * as refHelper from './ref-helper'
1010
import * as stateHelper from './state-helper'
11+
import * as urlHelper from './url-helper'
1112
import {IGitCommandManager} from './git-command-manager'
1213
import {IGitSourceSettings} from './git-source-settings'
1314

14-
const hostname = 'github.com'
15-
1615
export async function getSource(settings: IGitSourceSettings): Promise<void> {
1716
// Repository URL
1817
core.info(
1918
`Syncing repository: ${settings.repositoryOwner}/${settings.repositoryName}`
2019
)
21-
const repositoryUrl = settings.sshKey
22-
? `git@${hostname}:${encodeURIComponent(
23-
settings.repositoryOwner
24-
)}/${encodeURIComponent(settings.repositoryName)}.git`
25-
: `https://${hostname}/${encodeURIComponent(
26-
settings.repositoryOwner
27-
)}/${encodeURIComponent(settings.repositoryName)}`
20+
const repositoryUrl = urlHelper.getFetchUrl(settings)
2821

2922
// Remove conflicting file path
3023
if (fsHelper.fileExistsSync(settings.repositoryPath)) {

src/github-api-helper.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as io from '@actions/io'
66
import * as path from 'path'
77
import * as retryHelper from './retry-helper'
88
import * as toolCache from '@actions/tool-cache'
9+
import * as urlHelper from './url-helper'
910
import {default as uuid} from 'uuid/v4'
1011
import {ReposGetArchiveLinkParams} from '@octokit/rest'
1112

@@ -74,7 +75,7 @@ async function downloadArchive(
7475
ref: string,
7576
commit: string
7677
): Promise<Buffer> {
77-
const octokit = new github.GitHub(authToken)
78+
const octokit = new github.GitHub(authToken, {baseUrl: urlHelper.getApiUrl()})
7879
const params: ReposGetArchiveLinkParams = {
7980
owner: owner,
8081
repo: repo,

src/url-helper.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import * as assert from 'assert'
2+
import {IGitSourceSettings} from './git-source-settings'
3+
import {URL} from 'url'
4+
5+
export function getApiUrl(): string {
6+
return process.env['GITHUB_API_URL'] || 'https://api.github.com'
7+
}
8+
9+
export function getFetchUrl(settings: IGitSourceSettings): string {
10+
assert.ok(
11+
settings.repositoryOwner,
12+
'settings.repositoryOwner must be defined'
13+
)
14+
assert.ok(settings.repositoryName, 'settings.repositoryName must be defined')
15+
const serviceUrl = getServerUrl()
16+
const encodedOwner = encodeURIComponent(settings.repositoryOwner)
17+
const encodedName = encodeURIComponent(settings.repositoryName)
18+
if (settings.sshKey) {
19+
return `git@${serviceUrl.hostname}:${encodedOwner}/${encodedName}.git`
20+
}
21+
22+
// "origin" is SCHEME://HOSTNAME[:PORT]
23+
return `${serviceUrl.origin}/${encodedOwner}/${encodedName}`
24+
}
25+
26+
export function getServerUrl(): URL {
27+
return new URL(process.env['GITHUB_URL'] || 'https://github.com')
28+
}

0 commit comments

Comments
 (0)