fix default branch for .wiki

This commit is contained in:
eric sciple 2020-06-17 17:44:27 -04:00
parent b4483adec3
commit 8aabf05e48
2 changed files with 32 additions and 12 deletions

21
dist/index.js vendored
View file

@ -9583,14 +9583,25 @@ function getDefaultBranch(authToken, owner, repo) {
return yield retryHelper.execute(() => __awaiter(this, void 0, void 0, function* () {
core.info('Retrieving the default branch name');
const octokit = new github.GitHub(authToken);
const response = yield octokit.repos.get({ owner, repo });
if (response.status != 200) {
throw new Error(`Unexpected response from GitHub API. Status: ${response.status}, Data: ${response.data}`);
let result;
try {
// Get the default branch from the repo info
const response = yield octokit.repos.get({ owner, repo });
result = response.data.default_branch;
assert.ok(result, 'default_branch cannot be empty');
}
catch (err) {
// Handle .wiki repo
if (err['status'] === 404 && repo.toUpperCase().endsWith('.WIKI')) {
result = 'master';
}
// Otherwise error
else {
throw err;
}
}
// Print the default branch
let result = response.data.default_branch;
core.info(`Default branch '${result}'`);
assert.ok(result, 'default_branch cannot be empty');
// Prefix with 'refs/heads'
if (!result.startsWith('refs/')) {
result = `refs/heads/${result}`;