public override CommandResult Execute() { if (Options.ReleaseName.Contains("/")) { return(Fail("Invalid release name")); } var baseBranch = Options.BaseBranch ?? GetBaseBranch(Options.ReleaseName); var versionInfo = new VersionInfo(Options.ReleaseName); var repo = AzureGitHelper.FindRepository(AzureContext, Context.Options.RepositoryName); var releaseBranchName = "release/" + Options.ReleaseName; if (gitClient.HasBranch(repo.Id, releaseBranchName)) { return(Fail("Release already exists.")); } if (!Confirm($"Confirm created branch {releaseBranchName} from {baseBranch}?")) { return(Canceled()); } AddStep(() => gitClient.CreateBranch(repo.Id, baseBranch, releaseBranchName)); AddStep(() => ConfigureNextReleaseOnMaster(gitClient, repo.Id, versionInfo)); return(ExecuteSteps()); }
private bool ConfigureNextReleaseOnMaster(GitHttpClient gitClient, Guid repoId, VersionInfo versionInfo) { var nextVersion = new VersionInfo(versionInfo.ToString()); nextVersion.NextMinor(); nextVersion.LastScript = GetLastScriptName(); var topicBranchName = "dev/config-release-" + nextVersion.ToString(); gitClient.CreateBranch(repoId, "master", topicBranchName); if (!GitHelper.Checkout(topicBranchName, true, true)) { return(false); } SaveFileVersion(nextVersion); if (!GitHelper.AddAllFiles() || !GitHelper.Commit($"Inicialização da release {nextVersion}") || !GitHelper.Sync()) { return(false); } CreatePullRequest(gitClient, repoId, topicBranchName, "master", nextVersion); return(true); }
public static GitRef CreateBranch(this GitHttpClient gitClient, Guid repoId, string sourceRefName, string fullBranchName) { var sourceRef = gitClient.GetBranch(repoId, sourceRefName); return(gitClient.CreateBranch(repoId, sourceRef, fullBranchName)); }