@@ -6114,6 +6114,12 @@ function getSource(settings) {
61146114 // Repository URL
61156115 core.info(`Syncing repository: ${settings.repositoryOwner}/${settings.repositoryName}`);
61166116 const repositoryUrl = urlHelper.getFetchUrl(settings);
6117+ // Determine the default branch
6118+ if (!settings.ref && !settings.commit) {
6119+ core.startGroup('Determining the default branch');
6120+ settings.ref = yield githubApiHelper.getDefaultBranch(settings.authToken, settings.repositoryOwner, settings.repositoryName);
6121+ core.endGroup();
6122+ }
61176123 // Remove conflicting file path
61186124 if (fsHelper.fileExistsSync(settings.repositoryPath)) {
61196125 yield io.rmRF(settings.repositoryPath);
@@ -9569,6 +9575,31 @@ function downloadRepository(authToken, owner, repo, ref, commit, repositoryPath)
95699575 });
95709576}
95719577exports.downloadRepository = downloadRepository;
9578+ /**
9579+ * Looks up the default branch name
9580+ */
9581+ function getDefaultBranch(authToken, owner, repo) {
9582+ return __awaiter(this, void 0, void 0, function* () {
9583+ return yield retryHelper.execute(() => __awaiter(this, void 0, void 0, function* () {
9584+ core.info('Retrieving the default branch name');
9585+ const octokit = new github.GitHub(authToken);
9586+ const response = yield octokit.repos.get({ owner, repo });
9587+ if (response.status != 200) {
9588+ throw new Error(`Unexpected response from GitHub API. Status: ${response.status}, Data: ${response.data}`);
9589+ }
9590+ // Print the default branch
9591+ let result = response.data.default_branch;
9592+ core.info(`Default branch '${result}'`);
9593+ assert.ok(result, 'default_branch cannot be empty');
9594+ // Prefix with 'refs/heads'
9595+ if (!result.startsWith('refs/')) {
9596+ result = `refs/heads/${result}`;
9597+ }
9598+ return result;
9599+ }));
9600+ });
9601+ }
9602+ exports.getDefaultBranch = getDefaultBranch;
95729603function downloadArchive(authToken, owner, repo, ref, commit) {
95739604 return __awaiter(this, void 0, void 0, function* () {
95749605 const octokit = new github.GitHub(authToken);
@@ -14471,9 +14502,6 @@ function getInputs() {
1447114502 result.ref = `refs/heads/${result.ref}`;
1447214503 }
1447314504 }
14474- if (!result.ref && !result.commit) {
14475- result.ref = 'refs/heads/master';
14476- }
1447714505 }
1447814506 // SHA?
1447914507 else if (result.ref.match(/^[0-9a-fA-F]{40}$/)) {
@@ -14508,7 +14536,7 @@ function getInputs() {
1450814536 core.debug(`submodules = ${result.submodules}`);
1450914537 core.debug(`recursive submodules = ${result.nestedSubmodules}`);
1451014538 // Auth token
14511- result.authToken = core.getInput('token');
14539+ result.authToken = core.getInput('token', { required: true } );
1451214540 // SSH
1451314541 result.sshKey = core.getInput('ssh-key');
1451414542 result.sshKnownHosts = core.getInput('ssh-known-hosts');
0 commit comments