コード例 #1
0
ファイル: compare.cs プロジェクト: Aifei-Liu/benchmarker
	static async Task<ParseObject> GetPullRequestBaselineRunSet (string pullRequestURL, Benchmarker.Common.Git.Repository repository, Config config)
	{
		var gitHubClient = GitHubInterface.GitHubClient;
		var match = Regex.Match (pullRequestURL, @"^https?://github\.com/mono/mono/pull/(\d+)/?$");
		if (match == null) {
			Console.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.SshUrl;
		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 ("[email protected]:mono/mono.git", "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);

		var configObj = await config.GetFromParse ();
		if (configObj == null) {
			Console.Error.WriteLine ("Error: The config does not exist.");
			Environment.Exit (1);
		}

		var machineObj = await RunSet.GetMachineFromParse ();
		if (machineObj == null) {
			Console.Error.WriteLine ("Error: The machine does not exist.");
			Environment.Exit (1);
		}

		var runSets = await ParseInterface.PageQueryWithRetry (() => ParseObject.GetQuery ("RunSet")
			.WhereEqualTo ("machine", machineObj)
			.WhereEqualTo ("config", configObj)
			.WhereDoesNotExist ("pullRequest")
			.Include ("commit"));
		Console.WriteLine ("{0} run sets", runSets.Count ());

		var runSetsByCommits = new Dictionary<string, ParseObject> ();
		foreach (var runSet in runSets) {
			var sha = runSet.Get<ParseObject> ("commit").Get<string> ("hash");
			if (runSetsByCommits.ContainsKey (sha)) {
				// FIXME: select between them?
				continue;
			}
			runSetsByCommits.Add (sha, runSet);
		}

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

		return null;
	}