Skip to content

Commit cd7feac

Browse files
committed
Use default branch (instead of hardcoded master) if none is provided when fetching last commit
1 parent 9752b9c commit cd7feac

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Symfony/src/Codebender/LibraryBundle/Handler/DefaultHandler.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public function checkGithubUpdates()
126126

127127
$branch = $lib->getBranch();
128128
if ($branch === null){
129-
$branch = 'master';
129+
$branch = ''; // not providing any branch will make git return the commits of the default branch
130130
}
131131

132132
$directoryInRepo = $lib->getInRepoPath();
@@ -160,6 +160,7 @@ public function checkGithubUpdates()
160160
* Fetches the last commit sha of a repo. `sha` parameter can either be the name of a branch, or a commit
161161
* sha. In the first case, the commit sha's of the branch are returned. In the second case, the commit sha's
162162
* of the default branch are returned, as long as the have been written after the provided commit.
163+
* Not providing any sha/branch will make Git API return the list of commits for the default branch.
163164
* The API can also use a path parameter, in which case only commits that affect a specific directory are returned.
164165
*
165166
* @param $gitOwner
@@ -168,14 +169,16 @@ public function checkGithubUpdates()
168169
* @param string $path
169170
* @return mixed
170171
*/
171-
public function getLastCommitFromGithub($gitOwner, $gitRepo, $sha = 'master', $path = '')
172+
public function getLastCommitFromGithub($gitOwner, $gitRepo, $sha = '', $path = '')
172173
{
173174
/*
174175
* See the docs here https://developer.github.com/v3/repos/commits/
175176
* for more info on the json returned.
176177
*/
177178
$url = "https://api.github.com/repos/" . $gitOwner . "/" . $gitRepo . "/commits";
178-
$queryParams = "?sha=". $sha;
179+
if ($path != '') {
180+
$queryParams = "?sha=" . $sha;
181+
}
179182
if ($path != '') {
180183
$queryParams .= "&path=$path";
181184
}

0 commit comments

Comments
 (0)