示例#1
0
        public void ValidateOwnersLines(TestAndExpected entry)
        {
            // create the content
            string content = $"{entry.LabelsLine}\r\n{entry.PathAndOwners}";

            CodeOwnerEntry coe = CodeOwnersFile.ParseContent(content).First();

            Assert.AreEqual(entry.ExpectedLabels, coe.PRLabels);
            Assert.AreEqual(entry.ExpectedOwners, coe.Owners);
            Assert.AreEqual(entry.ExpectedPath, coe.PathExpression);
        }
示例#2
0
        public void ParseInvalidEntry()
        {
            // no path and owners
            var entry = new TestAndExpected("", "# PRLabel: %label1 %label2", string.Empty, new string[] { }, new string[] { "label1", "label2" });

            // create the content
            string content = $"{entry.LabelsLine}\r\n{entry.PathAndOwners}";

            CodeOwnerEntry coe = CodeOwnersFile.ParseContent(content).FirstOrDefault();

            Assert.IsNull(coe);
        }
示例#3
0
        /// <summary>
        /// Looks for CODEOWNERS in the main branch of the given repo URL
        /// </summary>
        /// <param name="repoUrl"></param>
        /// <returns></returns>
        private async Task <List <CodeOwnerEntry> > GetCodeownersFileImpl(Uri repoUrl)
        {
            // Gets the repo path from the URL
            var relevantPathParts = repoUrl.Segments.Skip(1).Take(2);
            var repoPath          = string.Join("", relevantPathParts);

            var codeOwnersUrl = $"https://raw.githubusercontent.com/{repoPath}/main/.github/CODEOWNERS";
            var result        = await httpClient.GetAsync(codeOwnersUrl);

            if (result.IsSuccessStatusCode)
            {
                logger.LogInformation("Retrieved CODEOWNERS file URL = {0}", codeOwnersUrl);
                return(CodeOwnersFile.ParseContent(await result.Content.ReadAsStringAsync()));
            }

            logger.LogWarning("Could not retrieve CODEOWNERS file URL = {0} ResponseCode = {1}", codeOwnersUrl, result.StatusCode);
            return(default);
示例#4
0
        public void ValidateCodeOwnersContent()
        {
            string content = @"#Comment


# ServiceLabel: %F1 %Service Attention
# PRLabel: %F1
/folder1/                                @user1

# ServiceLabel: %F2 %Service Attention
# PRLabel: %F2
/folder2/                                @user2

# ServiceLabel: %Service Attention %F3
/folder3/                                   @user3 @user1

# PRLabel: %F4 %Service Attention
/folder4/                                   @user4

/folder5/                                   @user5

# ServiceLabel: %MyService
#/<NotInRepo>/           @user6


# ServiceLabel: %MyService
# CommentedLine           @user7


/folder6            @user7


# ServiceLabel: %MyService
/folder8           @user6  #This has comment at the end
";

            List <CodeOwnerEntry> entries = CodeOwnersFile.ParseContent(content);

            Assert.AreEqual(8, entries.Count);


            Assert.AreEqual("F1", entries[0].PRLabels[0]);
            Assert.AreEqual("F1", entries[0].ServiceLabels[0]);
            Assert.AreEqual("Service Attention", entries[0].ServiceLabels[1]);

            Assert.AreEqual("F2", entries[1].PRLabels[0]);
            Assert.AreEqual("F2", entries[1].ServiceLabels[0]);
            Assert.AreEqual("Service Attention", entries[1].ServiceLabels[1]);
            Assert.AreEqual("/folder2/", entries[1].PathExpression);

            Assert.AreEqual("Service Attention", entries[2].ServiceLabels[0]);
            Assert.AreEqual(0, entries[2].PRLabels.Count);
            Assert.AreEqual("F3", entries[2].ServiceLabels[1]);

            Assert.AreEqual("F4", entries[3].PRLabels[0]);
            Assert.AreEqual(0, entries[3].ServiceLabels.Count);
            Assert.AreEqual("Service Attention", entries[3].PRLabels[1]);

            Assert.AreEqual(0, entries[4].ServiceLabels.Count);
            Assert.AreEqual(0, entries[4].PRLabels.Count);
            Assert.AreEqual("/folder5/", entries[4].PathExpression);

            Assert.AreEqual(1, entries[5].ServiceLabels.Count);
            Assert.AreEqual(0, entries[5].PRLabels.Count);
            Assert.AreEqual("#/<NotInRepo>/", entries[5].PathExpression);

            Assert.AreEqual(1, entries[6].ServiceLabels.Count);
            Assert.AreEqual(0, entries[6].PRLabels.Count);
            Assert.AreEqual("/folder6", entries[6].PathExpression);

            Assert.AreEqual(1, entries[7].ServiceLabels.Count);
            Assert.AreEqual(0, entries[7].PRLabels.Count);
            Assert.AreEqual("/folder8", entries[7].PathExpression);
            Assert.AreEqual("user6", entries[7].Owners[0]);
        }