Exemplo n.º 1
0
        public async static Task <bool> CompleteCommit(Config cfg, Commit commit)
        {
            if (commit.Product.Name == "mono" && !cfg.NoMono)
            {
                var binaryProtocolFile = cfg.ProducesBinaryProtocol ? "/tmp/binprot.dummy" : null;
                var info = NewProcessStartInfo(cfg, binaryProtocolFile);
                if (!String.IsNullOrWhiteSpace(info.FileName))
                {
                    /* Run without timing with --version */
                    info.Arguments = "--version";

                    Console.Out.WriteLine("\t$> {0} {1} {2}", PrintableEnvironmentVariables(info), info.FileName, info.Arguments);

                    var process      = Process.Start(info);
                    var version      = Task.Run(() => new StreamReader(process.StandardOutput.BaseStream).ReadToEnd()).Result;
                    var versionError = Task.Run(() => new StreamReader(process.StandardError.BaseStream).ReadToEnd()).Result;

                    process.WaitForExit();
                    process.Close();

                    var line  = version.Split(new char[] { '\n' }, 2) [0];
                    var regex = new Regex("^Mono JIT.*\\((.*)/([0-9a-f]+) (.*)\\)");
                    var match = regex.Match(line);

                    if (match.Success)
                    {
                        commit.Branch = match.Groups [1].Value;
                        var hash = match.Groups [2].Value;
                        if (commit.Hash != null)
                        {
                            if (!commit.Hash.StartsWith(hash))
                            {
                                Console.Error.WriteLine("Error: Commit hash for mono specified on command line does not match the one reported with --version.");
                                return(false);
                            }
                        }
                        else
                        {
                            commit.Hash = hash;
                        }
                        var date = match.Groups [3].Value;
                        Console.WriteLine("branch: " + commit.Branch + " hash: " + commit.Hash + " date: " + date);
                    }
                }

                if (commit.Branch == "(detached")
                {
                    commit.Branch = null;
                }

                try {
                    var gitRepoDir = Path.GetDirectoryName(cfg.Mono);
                    var repo       = new Repository(gitRepoDir);
                    var gitHash    = repo.RevParse(commit.Hash);
                    if (gitHash == null)
                    {
                        Console.WriteLine("Could not get commit " + commit.Hash + " from repository");
                    }
                    else
                    {
                        Console.WriteLine("Got commit " + gitHash + " from repository");

                        if (commit.Hash != null && commit.Hash != gitHash)
                        {
                            Console.Error.WriteLine("Error: Commit hash specified on command line does not match the one from the git repository.");
                            return(false);
                        }

                        commit.Hash          = gitHash;
                        commit.MergeBaseHash = repo.MergeBase(commit.Hash, "master");
                        commit.CommitDate    = repo.CommitDate(commit.Hash);

                        if (commit.CommitDate == null)
                        {
                            Console.Error.WriteLine("Error: Could not get commit date from the git repository.");
                            return(false);
                        }

                        Console.WriteLine("Commit {0} merge base {1} date {2}", commit.Hash, commit.MergeBaseHash, commit.CommitDate);
                    }
                } catch (Exception) {
                    Console.WriteLine("Could not get git repository");
                }
            }

            if (commit.Hash == null)
            {
                Console.Error.WriteLine("Error: cannot parse mono version and no commit given.");
                return(false);
            }

            Octokit.Commit gitHubCommit = await ResolveFullHashViaGithub(commit);

            if (gitHubCommit == null)
            {
                Console.WriteLine("Could not get commit " + commit.Hash + " from GitHub");
            }
            else
            {
                commit.Hash = gitHubCommit.Sha;
                if (commit.CommitDate == null)
                {
                    commit.CommitDate = gitHubCommit.Committer.Date.DateTime.ToLocalTime();
                }
                Console.WriteLine("Got commit " + commit.Hash + " from GitHub");
            }

            if (commit.CommitDate == null)
            {
                Console.Error.WriteLine("Error: Could not get a commit date.");
                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
    static async Task <Tuple <long, string> > GetPullRequestBaselineRunSetId(Product product, string pullRequestURL, compare.Repository repository, Config config)
    {
        var gitHubClient = GitHubInterface.GitHubClient;
        var match        = Regex.Match(pullRequestURL, product.PullRequestRegexp);

        if (match == null)
        {
            Console.Error.WriteLine("Error: Cannot parse pull request URL.");
            Environment.Exit(1);
        }
        var pullRequestNumber = Int32.Parse(match.Groups [1].Value);

        Console.WriteLine("pull request {0}", pullRequestNumber);

        var pullRequest = await gitHubClient.PullRequest.Get("mono", "mono", pullRequestNumber);

        var prRepo   = pullRequest.Head.Repository.CloneUrl;
        var prBranch = pullRequest.Head.Ref;

        var prSha = repository.Fetch(prRepo, prBranch);

        if (prSha == null)
        {
            Console.Error.WriteLine("Error: Could not fetch pull request branch {0} from repo {1}", prBranch, prRepo);
            Environment.Exit(1);
        }

        var masterSha = repository.Fetch(product.GitRepositoryUrl, "master");

        if (masterSha == null)
        {
            Console.Error.WriteLine("Error: Could not fetch master.");
            Environment.Exit(1);
        }

        var baseSha = repository.MergeBase(prSha, masterSha);

        if (baseSha == null)
        {
            Console.Error.WriteLine("Error: Could not determine merge base of pull request.");
            Environment.Exit(1);
        }

        Console.WriteLine("Merge base sha is {0}", baseSha);

        var revList = repository.RevList(baseSha);

        if (revList == null)
        {
            Console.Error.WriteLine("Error: Could not get rev-list for merge base {0}.", baseSha);
            Environment.Exit(1);
        }
        Console.WriteLine("{0} commits in rev-list", revList.Length);

        // FIXME: also support `--machine`
        var hostarch = compare.Utils.LocalHostnameAndArch();
        var machine  = new Machine {
            Name = hostarch.Item1, Architecture = hostarch.Item2
        };

        JArray runsets = await HttpApi.GetRunsets(machine.Name, config.Name);

        if (runsets == null)
        {
            Console.Error.WriteLine("Error: Could not get run sets.");
            Environment.Exit(1);
        }

        var runSetIdsByCommits = new Dictionary <string, long> ();

        foreach (var rs in runsets)
        {
            var id     = rs ["ID"].ToObject <long> ();
            var commit = rs ["MainProduct"] ["Commit"].ToObject <string> ();
            runSetIdsByCommits [commit] = id;
        }

        Console.WriteLine("{0} run sets", runSetIdsByCommits.Count);

        foreach (var sha in revList)
        {
            if (runSetIdsByCommits.ContainsKey(sha))
            {
                Console.WriteLine("tested base commit is {0}", sha);
                return(Tuple.Create(runSetIdsByCommits [sha], baseSha));
            }
        }

        return(null);
    }
Exemplo n.º 3
0
		public async static Task<bool> CompleteCommit (Config cfg, Commit commit)
		{
			if (commit.Product.Name == "mono" && !cfg.NoMono) {
				var binaryProtocolFile = cfg.ProducesBinaryProtocol ? "/tmp/binprot.dummy" : null;
				var info = NewProcessStartInfo (cfg, binaryProtocolFile);
				if (!String.IsNullOrWhiteSpace (info.FileName)) {
					/* Run without timing with --version */
					info.Arguments = "--version";

					Console.Out.WriteLine ("\t$> {0} {1} {2}", PrintableEnvironmentVariables (info), info.FileName, info.Arguments);

					var process = Process.Start (info);
					var version = Task.Run (() => new StreamReader (process.StandardOutput.BaseStream).ReadToEnd ()).Result;
					var versionError = Task.Run (() => new StreamReader (process.StandardError.BaseStream).ReadToEnd ()).Result;

					process.WaitForExit ();
					process.Close ();

					var line = version.Split (new char[] { '\n' }, 2) [0];
					var regex = new Regex ("^Mono JIT.*\\((.*)/([0-9a-f]+) (.*)\\)");
					var match = regex.Match (line);

					if (match.Success) {
						commit.Branch = match.Groups [1].Value;
						var hash = match.Groups [2].Value;
						if (commit.Hash != null) {
							if (!commit.Hash.StartsWith (hash)) {
								Console.Error.WriteLine ("Error: Commit hash for mono specified on command line does not match the one reported with --version.");
								return false;
							}
						} else {
							commit.Hash = hash;
						}
						var date = match.Groups [3].Value;
						Console.WriteLine ("branch: " + commit.Branch + " hash: " + commit.Hash + " date: " + date);
					}
				}

				if (commit.Branch == "(detached")
					commit.Branch = null;

				try {
					var gitRepoDir = Path.GetDirectoryName (cfg.Mono);
					var repo = new Repository (gitRepoDir);
					var gitHash = repo.RevParse (commit.Hash);
					if (gitHash == null) {
						Console.WriteLine ("Could not get commit " + commit.Hash + " from repository");
					} else {
						Console.WriteLine ("Got commit " + gitHash + " from repository");

						if (commit.Hash != null && commit.Hash != gitHash) {
							Console.Error.WriteLine ("Error: Commit hash specified on command line does not match the one from the git repository.");
							return false;
						}

						commit.Hash = gitHash;
						commit.MergeBaseHash = repo.MergeBase (commit.Hash, "master");
						commit.CommitDate = repo.CommitDate (commit.Hash);

						if (commit.CommitDate == null) {
							Console.Error.WriteLine ("Error: Could not get commit date from the git repository.");
							return false;
						}

						Console.WriteLine ("Commit {0} merge base {1} date {2}", commit.Hash, commit.MergeBaseHash, commit.CommitDate);
					}
				} catch (Exception) {
					Console.WriteLine ("Could not get git repository");
				}
			}

			if (commit.Hash == null) {
				Console.Error.WriteLine ("Error: cannot parse mono version and no commit given.");
				return false;
			}

			Octokit.Commit gitHubCommit = await ResolveFullHashViaGithub (commit);

			if (gitHubCommit == null) {
				Console.WriteLine ("Could not get commit " + commit.Hash + " from GitHub");
			} else {
				commit.Hash = gitHubCommit.Sha;
				if (commit.CommitDate == null)
					commit.CommitDate = gitHubCommit.Committer.Date.DateTime.ToLocalTime ();
				Console.WriteLine ("Got commit " + commit.Hash + " from GitHub");
			}

			if (commit.CommitDate == null) {
				Console.Error.WriteLine ("Error: Could not get a commit date.");
				return false;
			}

			return true;
		}