private bool HasReleaseBranch(string release) { var project = AzureProjectHelper.FindDefaultProject(AzureContext); var repo = AzureGitHelper.FindRepository(AzureContext, project.Id, Context.Options.RepositoryName); return(AzureContext.Connection.GetClient <GitHttpClient>().GetRefsAsync(repo.Id, filter: "heads/release/" + release).Result.FirstOrDefault() != null); }
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()); }
public override CommandResult Execute() { if (Options.WorkItemId <= 0) { throw new FigException("Invalid workitem ID."); } var project = AzureProjectHelper.FindDefaultProject(AzureContext); var repo = AzureGitHelper.FindRepository(AzureContext, project.Id, Context.Options.RepositoryName); var defaultBranchName = AzureGitHelper.WithoutRefsPrefix(repo.DefaultBranch); var defaultBranch = gitClient.GetRefsAsync(repo.Id, filter: defaultBranchName).Result.First(); var workitem = GetWorkItem(Options.WorkItemId); var relatedWorkitems = GetAllRelatedWorkdItems(workitem); var workItemsReleaseVersion = GetReleaseVersionFromWorkItems(relatedWorkitems); if (!string.IsNullOrEmpty(Options.Release) && !string.IsNullOrEmpty(workItemsReleaseVersion) && workItemsReleaseVersion != Options.Release) { throw new FigException("The reported release is different from the linked release in the workitems"); } var releaseBranchName = workItemsReleaseVersion ?? Options.Release; var parentWorkItem = relatedWorkitems.FirstOrDefault(); var releaseBranch = GetReleaseBranch(repo.Id, releaseBranchName); var branchName = GetBranchName(parentWorkItem, releaseBranch); var branchPatch = "heads/dev/" + branchName; var fullBranchPatch = "refs/" + branchPatch; var newBranch = gitClient.GetRefsAsync(repo.Id, filter: branchPatch).Result.FirstOrDefault(); if (newBranch == null || !newBranch.Name.EndsWith(branchPatch)) { if (!Confirm("Confirm branch creation: {0} [Enter]", branchName)) { return(Canceled()); } newBranch = CreateBranch(repo, releaseBranch ?? defaultBranch, fullBranchPatch, branchName); } LinkWorkItems(project, repo, newBranch, branchName, relatedWorkitems); StartFirstTask(workitem, relatedWorkitems); ConfigureLocalGit(branchName); if (!Options.NoPrune) { ClearLocalBranches(); } var result = Ok(); if (Options.RunDbScripts) { result = MigrateDatabase(); } return(result); }
public override CommandResult Execute() { if (string.IsNullOrEmpty(Options.TargetBranch)) { Options.TargetBranch = "master"; } var gitHttpClient = AzureContext.Connection.GetClient <GitHttpClient>(); var project = AzureProjectHelper.FindDefaultProject(AzureContext); var repo = AzureGitHelper.FindRepository(AzureContext, project.Id, Context.Options.RepositoryName); var pullRequest = gitHttpClient.GetPullRequestAsync(repo.Id, Options.PullRequestId).Result; if (pullRequest == null) { return(Fail("Pull request not found.")); } if (pullRequest.Status != PullRequestStatus.Completed) { return(Fail("Pull request not completed")); } var topicBranchName = pullRequest.SourceRefName.Replace("refs/heads/", "") + "-on-" + Options.TargetBranch.Replace("/", "-"); var pullRequestTargetBranch = pullRequest.TargetRefName.Replace("refs/heads/", ""); if (pullRequestTargetBranch == Options.TargetBranch) { return(Fail($"The pull request branch is same target branch [{Options.TargetBranch}]")); } if (!Confirm($"Confirm merge {pullRequestTargetBranch} to {Options.TargetBranch}? Will be created {topicBranchName}")) { return(Canceled()); } if (!GitHelper.MergeInProgress()) { AddStep(() => GitHelper.Checkout(pullRequestTargetBranch, true)); AddStep(() => GitHelper.CreateBranch(Options.TargetBranch, topicBranchName, true)); AddStep(() => GitHelper.Merge(pullRequestTargetBranch)); } AddStep(() => GitHelper.Commit($"Merge {pullRequestTargetBranch} to {Options.TargetBranch}", checkHasChangesBeforeCommit: true)); AddStep(() => GitHelper.PushBranch()); AddStep(() => GitHelper.Sync()); AddStep(() => CreatePullRequest(gitHttpClient, repo.Id, pullRequest, topicBranchName, Options.TargetBranch, pullRequestTargetBranch)); return(ExecuteSteps()); }