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 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.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); }
private void CreatePullRequest(GitHttpClient client, Guid repoId, string sourceBranch, string targetBranch, VersionInfo versionInfo) { client.CreatePullRequestAsync(new GitPullRequest() { SourceRefName = AzureGitHelper.WithRefsAndHeadsPrefix(sourceBranch), TargetRefName = AzureGitHelper.WithRefsAndHeadsPrefix(targetBranch), Title = $"Inicialização da release {versionInfo}" }, repoId).Wait(); }
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()); }
private CommandResult CreatePullRequest(GitHttpClient client, Guid repoId, GitPullRequest pullRequestBase, string topicBranchName, string targetBranch, string pullRequestTargetBranch) { var pullRequest = client.CreatePullRequestAsync(new GitPullRequest() { SourceRefName = AzureGitHelper.WithRefsAndHeadsPrefix(topicBranchName), TargetRefName = AzureGitHelper.WithRefsAndHeadsPrefix(targetBranch), Title = $"Merge {pullRequestTargetBranch} to {Options.TargetBranch}", Description = $"Originated by Pull Request {pullRequestBase.PullRequestId} - {pullRequestBase.Title}" }, repoId).Result; var url = AzureGitHelper.BuildUrl(Context, "/pullrequest/" + pullRequest.PullRequestId); BrowserHelper.OpenUrl(url); return(Ok()); }
public override CommandResult Execute() { var currentBranch = GitHelper.GetCurrentBranchName(); var targetBranch = Options.TargetBranch ?? "master"; if (currentBranch.Contains("-on-")) { var targetBranchFromCurrentBranch = currentBranch.Substring(currentBranch.LastIndexOf("-on-") + 4).Replace("release-", "release/"); if (targetBranch?.ToLower() != "master" && targetBranch != targetBranchFromCurrentBranch) { return(Fail("Differents Target branch")); } targetBranch = targetBranchFromCurrentBranch; } var url = AzureGitHelper.BuildUrl(Context, "/pullrequestcreate?sourceRef={0}&targetRef={1}", currentBranch, targetBranch); BrowserHelper.OpenUrl(url); return(CommandResult.Ok()); }
private object GetFirstReleaseBranchByCommit(Guid repoId, GitCommitRef lastCommit, List <GitRef> releaseBranches) { foreach (var releaseBranch in releaseBranches) { var newBranchVersionDescriptor = new GitVersionDescriptor() { VersionType = GitVersionType.Branch, Version = AzureGitHelper.WithoutRefsAndHeadsPrefix(releaseBranch.Name) }; var criteria = new GitQueryCommitsCriteria() { Ids = new List <string>() { lastCommit.CommitId }, Top = 1, ItemVersion = newBranchVersionDescriptor }; if (gitClient.GetCommitsAsync(repoId, criteria, top: 1).Result.Any()) { return(releaseBranch); } } return(null); }
private void ConfigureRepository(FigOptions figOptions) { InitializeAzureContext(); figOptions.RepositoryName = GitHelper.GetRemoteRepositoryName(); figOptions.RepositoryId = AzureGitHelper.FindRepositoryId(AzureContext, AzureProjectHelper.FindDefaultProjectId(AzureContext), figOptions.RepositoryName)?.ToString(); }