Esempio n. 1
0
        public override object GetDefault(VerbExecutionContext context)
        {
            var gitDir = GitRepo.Find(".");
            if (gitDir == null)
                throw new InvalidOperationException("Could not locate a git repository in the current directory or any of its ancestors.");

            // Read git repo from current path, if it exists.
            try
            {
                var lines = File.ReadAllLines(Path.Combine(gitDir, ".git", "config"));
                var remotes = lines
                    .Select((line, i) => new { Line = line, Index = i })
                    // Only those lines that define a remote
                    .Where(line => line.Line.StartsWith("[remote "))
                    // Grab url from following line.
                    .Select(line => new { Remote = line.Line.Substring(9, line.Line.Length - 11), Url = lines[line.Index + 1].Trim() })
                    .ToList();

                var remote = remotes
                    .FirstOrDefault(x =>
                        x.Remote == "origin" ||
                        x.Remote == "upstream");

                if (remote == null)
                    remote = remotes.FirstOrDefault();

                if (remote != null)
                {
                    var match = urlExpr.Match(remote.Url);
                    if (match.Success)
                        return GetDefault(match.Groups["owner"].Value, match.Groups["repository"].Value);
                }
            }
            catch (IOException) { }

            return null;
        }
Esempio n. 2
0
 public override object GetDefault(VerbExecutionContext context)
 {
     throw new NotImplementedException();
 }
Esempio n. 3
0
 public override object GetDefault(VerbExecutionContext context)
 {
     return "def2";
 }
Esempio n. 4
0
 public override object GetDefault(VerbExecutionContext context)
 {
     return ConfigurationManager.AppSettings["apiToken"];
 }