예제 #1
0
        public async Task <WorkItem> CreateWorkItem(
            [ActivityTrigger] Tuple <JObject, PullRequestStateContext> createWorkItemParameter,
            ILogger log
            )
        {
            var parentReviewComment     = createWorkItemParameter.Item1;
            var pullRequestStateContext = createWorkItemParameter.Item2;


            var currentReviewComment = pullRequestStateContext.CreatedReviewComment
                                       .FirstOrDefault(p => p.CommentId == (int)parentReviewComment["Id"]);
            var issues =
                await _sonarCloudRepository.GetIssues(pullRequestStateContext.PullRequestNumber.ToString(), currentReviewComment.ProjectKey, currentReviewComment.IssueId);

            var currentIssue = issues.issues.FirstOrDefault();

            var body     = $"<b>{currentIssue.type}</b></p>{currentIssue.message}</p>See more <a href=\"https://sonarcloud.io/project/issues?id={currentReviewComment.ProjectKey}&open={currentIssue.key}&pullRequest={pullRequestStateContext.PullRequestNumber}&resolved=false\">details</a>.";
            var workItem = new WorkItemSource()
            {
                Title       = $"SonarCloud GitHub Issue PR {pullRequestStateContext.PullRequestNumber}: {currentIssue.message}",
                Description = body
            };
            WorkItem createdWorkItem = await _workItemRepository.CreateWorkItem(workItem);

            return(createdWorkItem);
        }
예제 #2
0
        public Task <WorkItem> CreateWorkItem(WorkItemSource workItem)
        {
            var project = "DevSecOps";
            var type    = "Bug";

            var document = workItem.ToJsonPatchDocument();

            return(client.CreateWorkItemAsync(document, project, type));
        }
예제 #3
0
        public async Task <WorkItem> CreateWorkItemAsync([ActivityTrigger] CreateWorkItemContext context)
        {
            var body           = $"<b>{context.Issue.Type}</b></p>{context.Issue.Message}</p>See more <a href=\"{context.Issue.Url}\">details</a>.";
            var workItemSource = new WorkItemSource()
            {
                Title =
                    $"{context.CreatedReviewComment.ScanProvider} Issue {BotConfiguration.RepositoryProvider} PR {context.PullRequestId}: {context.Issue.Message}",
                Description = body,
                Project     = AzureDevOpsConfiguration.Project,
                Type        = "Bug"
            };
            var workItem = await _workItemRepository.CreateWorkItem(workItemSource);

            return(new WorkItem()
            {
                Id = workItem.Id.ToString(),
                Uri = ((Microsoft.VisualStudio.Services.WebApi.ReferenceLink)workItem.Links.Links["html"]).Href,
                WorkItemProvider = AzureDevOpsConfiguration.ProviderName
            });
        }
예제 #4
0
        public void ConvertToJsonPatchDocument()
        {
            var workItem = new WorkItemSource()
            {
                Title       = "foo",
                Description = "bar"
            };

            JsonPatchDocument document = workItem.ToJsonPatchDocument();


            // Title
            Assert.Equal(Operation.Add, document[0].Operation);
            Assert.Equal("/fields/System.Title", document[0].Path);
            Assert.Equal("foo", document[0].Value as string);
            // Description
            Assert.Equal(Operation.Add, document[1].Operation);
            Assert.Equal("/fields/Microsoft.VSTS.TCM.SystemInfo", document[1].Path);
            Assert.Equal("bar", document[1].Value as string);
        }