GetProject() public method

public GetProject ( int id ) : NGitLab.Models.Project
id int
return NGitLab.Models.Project
Example #1
0
        static void ProcessMergeRequestHook(GitLabWrapper gitLabWrapper, string serviceUser, MergeRequestHookClient hook, bool supportSendingMessages, string farmTaskName) {
            Log.Message($"Merge hook title: {hook.Attributes.Description}");
            Log.Message($"Merge hook state: {hook.Attributes.State}");

            var targetProject = gitLabWrapper.GetProject(hook.Attributes.TargetProjectId);
            var mergeRequest = gitLabWrapper.GetMergeRequest(targetProject, hook.Attributes.Id);
            if (supportSendingMessages)
                SendMessage(serviceUser, hook.Json, farmTaskName);

            if (!IsOpenedState(hook))
                return;

            Log.Message($"Merge hook action: {hook.Attributes.Action}");
            Log.Message($"Merge hook merge status: {hook.Attributes.MergeStatus}");
            Log.Message($"Merge hook author: {gitLabWrapper.GetUser(hook.Attributes.AuthorId).Name}.");
            Log.Message($"Merge hook target branch: {hook.Attributes.TargetBranch}.");
            Log.Message($"Merge hook sourceBranch branch: {hook.Attributes.SourceBranch}.");

            if (ShouldForceSyncTask(mergeRequest, hook)) {
                ForceSyncBuild(gitLabWrapper, mergeRequest, targetProject, hook);
                return;
            }
        }
Example #2
0
        static void ProcessBuildHook(GitLabWrapper gitLabWrapper, string serviceUser, BuildHookClient hook, bool supportSendingMessages, string farmTaskName) {
            Log.Message($"Build hook title: {hook.BuildName}");
            Log.Message($"Build hook status: {hook.Status}");

            if (supportSendingMessages)
                SendMessage(serviceUser, hook.Json, farmTaskName);

            if (hook.Status == BuildStatus.success) {
                Project project = gitLabWrapper.GetProject(hook.ProjectId);
                if (project == null) {
                    Log.Message($"Can`t find project {hook.ProjectName}.");
                    return;
                }
                Log.Message($"Project: {project.PathWithNamespace}");
                var mergeRequest = CalcMergeRequest(gitLabWrapper, hook, project);
                if (mergeRequest == null) {
                    Log.Message("Can`t find merge request.");
                    return;
                }
                Log.Message($"Merge request: id = {mergeRequest.Id} title = {mergeRequest.Title}");
                Log.Message($"Merge request state = {mergeRequest.State}");
                if (mergeRequest.State == "opened" || mergeRequest.State == "reopened") {
                    var latestCommit = gitLabWrapper.GetMergeRequestCommits(mergeRequest).FirstOrDefault();
                    if (latestCommit == null) {
                        Log.Message("Wrong merge request found.");
                        return;
                    }
                    Log.Message($"Merge request latest commit sha = {latestCommit.Id}");
                    if (!latestCommit.Id.Equals(new Sha1(hook.Commit.Id))) {
                        Log.Message($"Additional commits has been added {hook.Commit.Id}");
                        return;
                    }

                    var xmlComments = gitLabWrapper.GetComments(mergeRequest).Where(x => IsXml(x.Note));
                    var options = xmlComments.Select(x => MergeRequestOptions.ConvertFromString(x.Note)).FirstOrDefault();
                    if (options?.ActionType == MergeRequestActionType.sync) {
                        Log.Message("Sync options found.");
                        var syncOptions = (MergeRequestSyncAction)options.Action;
                        Log.Message($"Sync options perform testing is {syncOptions.PerformTesting}");
                        Log.Message($"Sync options assign to service is {syncOptions.AssignToSyncService}");
                        Log.Message($"Sync options sync task is {syncOptions.SyncTask}");
                        Log.Message($"Sync options sync service is {syncOptions.SyncService}");
                        if (syncOptions.PerformTesting && syncOptions.AssignToSyncService) {
                            gitLabWrapper.UpdateMergeRequestAssignee(mergeRequest, syncOptions.SyncService);
                            ForceBuild(syncOptions.SyncTask);
                        }
                        return;
                    }
                    Log.Message("Sync options not found.");
                }
            }
        }