public MergeRequest CreateMergeRequest(Project origin, Project upstream, string title, string description, string user, string sourceBranch, string targetBranch) { var mergeRequestClient = this.client.GetMergeRequest(origin.Id); var mergeRequest = mergeRequestClient.Create(new MergeRequestCreate() { Title = title, Description = description, SourceBranch = sourceBranch, TargetBranch = targetBranch, TargetProjectId = upstream.Id, }); return mergeRequest; }
ProjectCreate CreateProject(out Project created, string name) { var p = new ProjectCreate { Description = "desc", ImportUrl = null, IssuesEnabled = true, MergeRequestsEnabled = true, Name = name, NamespaceId = null, SnippetsEnabled = true, VisibilityLevel = VisibilityLevel.Public, WallEnabled = true, WikiEnabled = true }; created = _projects.Create(p); return p; }
public void SetUp() { Project = Config.Connect().Projects.Owned.First(project => project.Name == "mergeme"); MergeRequestClient = Config.Connect().GetMergeRequest(Project.Id); }
static List<MergeRequest> GetMergeRequests(GitLabWrapper gitLabWrapper, string branchName, string userName, Project project) { return gitLabWrapper.GetMergeRequests(project, x => x.TargetBranch == branchName).Where(x => x.Assignee?.Name == userName).ToList(); }
static void ForceSyncBuild(GitLabWrapper gitLabWrapper, MergeRequest mergeRequest, Project targetProject, MergeRequestHookClient hook) { var xmlComments = gitLabWrapper.GetComments(mergeRequest).Where(x => IsXml(x.Note)); var options = xmlComments.Select(x => MergeRequestOptions.ConvertFromString(x.Note)).FirstOrDefault(); if (options != null && options.ActionType == MergeRequestActionType.sync) { var action = (MergeRequestSyncAction)options.Action; if (action.PerformTesting) { Log.Message("Check build status before force build."); var commit = gitLabWrapper.GetMergeRequestCommits(mergeRequest).FirstOrDefault(); var build = commit != null ? gitLabWrapper.GetBuilds(mergeRequest, commit.Id).FirstOrDefault() : null; var buildStatus = build?.Status ?? BuildStatus.undefined; Log.Message($"Build status = {buildStatus}."); if (buildStatus == BuildStatus.success) ForceBuild(action.SyncTask); return; } Log.Message("Build forces without checking tests status."); ForceBuild(action.SyncTask); return; } string task = FarmIntegrator.FindTask($"{mergeRequest.TargetBranch}@{targetProject.PathWithNamespace}"); if (!string.IsNullOrEmpty(task)) { Log.Message($"Sync task {task} found by heuristic."); ForceBuild(task); return; } Log.Message("Merge request can`t be merged because merge request notes has no farm config."); Log.Message(""); }
static MergeRequest CalcMergeRequest(GitLabWrapper gitLabWrapper, BuildHookClient hook, Project project) { foreach (var checkProject in gitLabWrapper.GetProjects()) { var mergeRequests = gitLabWrapper.GetMergeRequests(checkProject, x => x.SourceProjectId == project.Id); var mergeRequest = mergeRequests.FirstOrDefault(x => x.SourceBranch == hook.Branch); if (mergeRequest != null) return mergeRequest; } return null; }
public void SetUp() { _project = Config.Connect().Projects.Owned.Single(); RepositoryClient = Config.Connect().GetRepository(_project.Id); }
public ProjectHook CreateProjectHook(Project project, Uri url, bool mergeRequestEvents, bool pushEvents, bool buildEvents) { var projectClient = client.GetRepository(project.Id); var projectHooks = projectClient.ProjectHooks; return projectHooks.Create(new ProjectHookUpsert() { MergeRequestsEvents = mergeRequestEvents, PushEvents = pushEvents, BuildEvents = buildEvents, Url = url, EnableSSLVerification = false}); }
public IEnumerable<ProjectHook> GetProjectHooks(Project project) { var repository = this.client.GetRepository(project.Id); return repository.ProjectHooks.All; }
public ProjectHook UpdateProjectHook(Project project, ProjectHook hook, Uri uri, bool mergeRequestEvents, bool pushEvents, bool buildEvents) { var repository = this.client.GetRepository(project.Id); return repository.ProjectHooks.Update(hook.Id, new ProjectHookUpsert() { Url = uri, MergeRequestsEvents = mergeRequestEvents, PushEvents = pushEvents, BuildEvents = buildEvents, EnableSSLVerification = false}); }
public IEnumerable<MergeRequest> GetMergeRequests(Project project, Func<MergeRequest, bool> mergeRequestsHandler = null) { mergeRequestsHandler = mergeRequestsHandler ?? (x => true); var mergeRequestsClient = client.GetMergeRequest(project.Id); return mergeRequestsClient.AllInState(MergeRequestState.opened).Where(x => mergeRequestsHandler(x)); }
public MergeRequest GetMergeRequest(Project project, int id) { var mergeRequestsClient = client.GetMergeRequest(project.Id); return mergeRequestsClient[id]; }
public IEnumerable<Branch> GetBranches(Project project) { var repo = this.client.GetRepository(project.Id); var branchesClient = repo.Branches; return branchesClient.All; }
public Branch GetBranch(Project project, string branch) { var repo = this.client.GetRepository(project.Id); var branchesClient = repo.Branches; try { return branchesClient[branch]; } catch { return branchesClient.All.FirstOrDefault(x => x.Name == branch); } }
public ProjectHook FindProjectHook(Project project, Func<ProjectHook, bool> projectHookHandler) { var projectClient = client.GetRepository(project.Id); var projectHooks = projectClient.ProjectHooks; return projectHooks.All.FirstOrDefault(projectHookHandler); }