Exemplo n.º 1
0
        public MergeRequestAdapterTests()
        {
            // Given
            string gitLabResponse = "[{'id':44126460,'iid':1,'project_id':15722380,'title':'Readme updated','description':'','state':'opened','created_at':'2019-12-06T12:55:01.316Z','updated_at':'2019-12-06T12:55:01.316Z','merged_by':null,'merged_at':null,'closed_by':null,'closed_at':null,'target_branch':'master','source_branch':'develop','user_notes_count':0,'upvotes':0,'downvotes':0,'assignee':null,'author':{'id':108019,'name':'Nicolas','username':'******','state':'active','avatar_url':'https://secure.gravatar.com/avatar/f4c52cfd67c861fd5c87c66704b88b3c?s=80&d=identicon','web_url':'https://gitlab.com/nicopaez'},'assignees':[],'source_project_id':15722380,'target_project_id':15722380,'labels':[],'work_in_progress':false,'milestone':null,'merge_when_pipeline_succeeds':false,'merge_status':'can_be_merged','sha':'0520da5b424a18e7c3af2318fa7141ee6e927b8f','merge_commit_sha':null,'squash_commit_sha':null,'discussion_locked':null,'should_remove_source_branch':null,'force_remove_source_branch':true,'reference':'!1','web_url':'https://gitlab.com/untref-ingsoft/tfi-cozzi/sample-repo1/merge_requests/1','time_stats':{'time_estimate':0,'total_time_spent':0,'human_time_estimate':null,'human_total_time_spent':null},'squash':false,'task_completion_status':{'count':0,'completed_count':0},'has_conflicts':false,'blocking_discussions_resolved':true,'approvals_before_merge':0}]";

            IEnumerable <GitLabMergeRequest> gitLabMergeRequest = JsonConvert.DeserializeObject <IEnumerable <GitLabMergeRequest> >(gitLabResponse);

            this.adaptee = gitLabMergeRequest.FirstOrDefault();

            // When
            MergeRequestAdapter adapter = new MergeRequestAdapter();

            this.expectedMergeRequest = adapter.GetMergeRequest(this.adaptee);
        }
Exemplo n.º 2
0
        public void Validate(GitLabMergeRequest mergeRequest)
        {
            var gitLabUrl          = Configuration["GitLabUrl"];
            var gitLabPrivateToken = Configuration["GitLabPrivateToken"];
            var labelForNoLabelMR  = Configuration["LabelForNoLabelMR"];

            if (string.IsNullOrEmpty(gitLabUrl))
            {
                Console.WriteLine("No GitLabUrl configured, look at appsettings.json and try again!");
                return;
            }

            if (string.IsNullOrEmpty(gitLabPrivateToken))
            {
                Console.WriteLine("No GitLabPrivateToken configured, look at appsettings.json and try again!");
                return;
            }

            if (string.IsNullOrEmpty(labelForNoLabelMR))
            {
                Console.WriteLine("No LabelForNoLabelMR configured, look at appsettings.json and try again!");
                return;
            }

            var newLabels = new List <string>();

            if (mergeRequest.labels.Length == 0)
            {
                Console.WriteLine("Merge request with no Label, assigning " + labelForNoLabelMR + " label");
                newLabels.Add(labelForNoLabelMR);
            }

            if (newLabels.Count > 0)
            {
                var putMRResource = new GitLabMergeRequestPutResource()
                {
                    labels = newLabels.ToArray()
                };

                gitLabUrl
                .AppendPathSegments("api", "v4")
                .AppendPathSegments("projects", mergeRequest.project.id, "merge_requests")
                .AppendPathSegment(mergeRequest.object_attributes.iid)
                .SetQueryParam("private_token", gitLabPrivateToken)
                .PutJsonAsync(putMRResource);
            }
        }
Exemplo n.º 3
0
 public void Dispose()
 {
     this.adaptee = null;
 }