Skip to content

Commit

Permalink
prevent default branch override for wikicompress
Browse files Browse the repository at this point in the history
  • Loading branch information
dabutvin committed Nov 11, 2019
1 parent 62eb33e commit 6e0e360
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions CompressImagesFunction/CompressImages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public static bool Run(CompressimagesParameters parameters, ICollector<CompressI

var repo = new Repository(parameters.LocalPath);
var remote = repo.Network.Remotes["origin"];
var isWikiCompress = parameters.CloneUrl.EndsWith(".wiki.git");

// check if we have the branch already or this is empty repo
try
Expand All @@ -64,7 +65,7 @@ public static bool Run(CompressimagesParameters parameters, ICollector<CompressI
}

// check if we should switch away from the default branch
if (parameters.Settings != null && !string.IsNullOrEmpty(parameters.Settings.DefaultBranchOverride))
if (!isWikiCompress && parameters.Settings != null && !string.IsNullOrEmpty(parameters.Settings.DefaultBranchOverride))
{
logger.LogInformation(
"CompressImagesFunction: default branch override for {Owner}/{RepoName} is {DefaultBranchOverride}",
Expand Down Expand Up @@ -103,7 +104,7 @@ public static bool Run(CompressimagesParameters parameters, ICollector<CompressI
}

// Add new compressMessage if we should compress Wiki
if (repoConfiguration.CompressWiki && parameters.CloneUrl.Contains(".wiki.git") == false)
if (repoConfiguration.CompressWiki && isWikiCompress == false)
{
logger.LogInformation("CompressImagesFunction: Adding Wiki image compression to queue for {Owner}/{RepoName}", parameters.RepoOwner, parameters.RepoName);
compressImagesMessages.Add(new CompressImagesMessage()
Expand All @@ -122,7 +123,7 @@ public static bool Run(CompressimagesParameters parameters, ICollector<CompressI
}

// Should not create branch if we are compressing Wiki
if (parameters.CloneUrl.Contains(".wiki.git") == false)
if (isWikiCompress == false)
{
// check out the branch
repo.CreateBranch(KnownGitHubs.BranchName);
Expand Down Expand Up @@ -166,8 +167,12 @@ public static bool Run(CompressimagesParameters parameters, ICollector<CompressI

repo.Refs.UpdateTarget(repo.Refs.Head, commitToKeep);

// Should not create branch if we are compressing Wiki
if (parameters.CloneUrl.Contains(".wiki.git") == false)
// Should use "master" if we are compressing Wiki
if (isWikiCompress)
{
var branchAgain = Commands.Checkout(repo, "master");
}
else
{
var branchAgain = Commands.Checkout(repo, KnownGitHubs.BranchName);
}
Expand Down Expand Up @@ -196,10 +201,20 @@ public static bool Run(CompressimagesParameters parameters, ICollector<CompressI
}

// push to GitHub
repo.Network.Push(remote, $"refs/heads/{KnownGitHubs.BranchName}", new PushOptions
if (isWikiCompress)
{
CredentialsProvider = credentialsProvider,
});
repo.Network.Push(remote, "refs/heads/master", new PushOptions
{
CredentialsProvider = credentialsProvider,
});
}
else
{
repo.Network.Push(remote, $"refs/heads/{KnownGitHubs.BranchName}", new PushOptions
{
CredentialsProvider = credentialsProvider,
});
}

return true;
}
Expand Down

0 comments on commit 6e0e360

Please sign in to comment.