Ejemplo n.º 1
0
        public void ValidateOwnersLines(TestAndExpected entry)
        {
            CodeOwnerEntry coe = new CodeOwnerEntry(entry.PathAndOwners, entry.LabelsLine);

            Assert.AreEqual(entry.ExpectedLabels, coe.Labels);
            Assert.AreEqual(entry.ExpectedOwners, coe.Owners);
            Assert.AreEqual(entry.ExpectedPath, coe.PathExpression);
        }
Ejemplo n.º 2
0
        private void TestExpectResult(List <string> expectReturn, string output)
        {
            CodeOwnerEntry codeOwnerEntry = JsonSerializer.Deserialize <CodeOwnerEntry>(output);
            List <string>  actualReturn   = codeOwnerEntry.Owners;

            Assert.AreEqual(expectReturn.Count, actualReturn.Count);
            for (int i = 0; i < actualReturn.Count; i++)
            {
                Assert.AreEqual(expectReturn[i], actualReturn[i]);
            }
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        private List <CodeOwnerEntry> ReadOwnersFromFile()
        {
            List <CodeOwnerEntry> entries = new List <CodeOwnerEntry>();
            string line;

            using (StreamReader sr = new StreamReader(_codeownersFile))
            {
                while ((line = sr.ReadLine()) != null)
                {
                    // Does the line start with '# PRLabel: "label1", "label2"

                    // Remove tabs and trim extra whitespace
                    line = NormalizeLine(line);

                    // Empty line, move on
                    if (string.IsNullOrEmpty(line))
                    {
                        continue;
                    }

                    CodeOwnerEntry entry = new CodeOwnerEntry();

                    // if we have the moniker in the line, parse the labels
                    if (line.StartsWith('#') &&
                        line.IndexOf(CodeOwnerEntry.LabelMoniker, System.StringComparison.OrdinalIgnoreCase) >= 0)
                    {
                        entry.ParseLabels(line);

                        // We need to read the next line
                        line = sr.ReadLine();

                        if (line == null)
                        {
                            break;
                        }

                        // Remove tabs and trim extra whitespace
                        line = NormalizeLine(line);
                    }

                    // If this is not a comment line.
                    if (line.IndexOf('#') == -1)
                    {
                        entry.ParseOwnersAndPath(line);
                    }

                    if (entry.IsValid)
                    {
                        entries.Add(entry);
                    }
                }
            }
            return(entries);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        private string ToConfigString(CodeOwnerEntry entry)
        {
            string result = s_configTemplate;

            result = result.Replace("###label###", entry.Labels.First());

            // at this point we should remove the leading '/' if any
            if (entry.PathExpression.StartsWith("/"))
            {
                entry.PathExpression = entry.PathExpression.Substring(1);
            }
            result = result.Replace("###srcFolders###", $"\"{entry.PathExpression}\"");

            return(result);
        }