Exemplo n.º 1
0
		/// <summary>
		/// Populates a submission branch with a pull request, and returns the 
		/// pull request number.
		/// </summary>
		public async Task<int> CreatePullRequestAsync(
			Commit commit,
			Checkpoint checkpoint)
		{
			var student = GetStudent(commit.Project, commit.User);
			var orgName = student.Classroom.GitHubOrganization;
			var repoName = checkpoint.Project.GetStudentRepoName(student);

			// Get the commits to use in the pull requests.
			var allCommits = await GetAllCommitsAsync(commit.Project, student);
			var submissionCommit = allCommits.SingleOrDefault(c => c.Sha == commit.Sha);
			var startingCommit = allCommits.Where(c => c.Parents.Count == 0)
				.OrderBy(c => c.Date)
				.FirstOrDefault();

			// Create a submission branch that initially just contains the starting commit.
			// This will be the destination of our new pull request.
			var destBranchName = checkpoint.Name;
			await _repoClient.CreateBranchAsync
			(
				orgName, 
				repoName, 
				destBranchName, 
				startingCommit.Sha
			);

			// Create a temporary source branch that initially contains the student's commit 
			// for the checkpoint, and all previous commits. This is the source of the pull request.
			var sourceBranchName = $"{checkpoint.Name}Source";
			await _repoClient.CreateBranchAsync
			(
				orgName,
				repoName,
				sourceBranchName,
				submissionCommit.Sha
			);

			// Create the pull request.
			var pullRequestTitle = $"{checkpoint.DisplayName} Submission";
			int pullRequestNumber = await _repoClient.CreatePullRequestAsync
			(
				orgName,
				repoName,
				pullRequestTitle,
				sourceBranchName,
				destBranchName
			);

			// Delete the temporary source branch.
			await _repoClient.DeleteBranchAsync(orgName, repoName, sourceBranchName);

			return pullRequestNumber;
		}
Exemplo n.º 2
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public SubmittedViewModel(
     Commit commit,
     string commitUrl,
     Checkpoint checkpoint,
     ITimeZoneProvider timeZoneProvider)
 {
     User = commit.User;
     Checkpoint = checkpoint;
     Submission = new SubmissionCandidateViewModel
     (
         commit,
         commitUrl,
         true /*previousSubmission*/,
         true /*defaultChoice*/,
         timeZoneProvider
     );
 }
 /// <summary>
 /// Constructor.
 /// </summary>
 public SubmissionCandidateViewModel(
     Commit commit,
     string commitUrl,
     bool previousSubmission,
     bool defaultChoice,
     ITimeZoneProvider timeZoneProvider)
 {
     CommitId = commit.Id;
     Sha = commit.Sha;
     DateCommitted = commit.PushDate.FormatLongDateTime(timeZoneProvider);
     GitHubUrl = commitUrl;
     BuildId = commit.Build.Id;
     PassingTests = commit.Build.TestResults.Count(t => t.Succeeded);
     CommitMessage = commit.Message;
     PreviousSubmission = previousSubmission;
     DefaultChoice = defaultChoice;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public PushEventCommit(GitHubPushEvent pushEvent, Commit commit)
 {
     PushEvent = pushEvent;
     Commit = commit;
 }
 /// <summary>
 /// Constructor.
 /// </summary>
 public BuildInProgressViewModel(Commit commit, TimeSpan estimatedDuration)
 {
     Commit = commit;
     EstimatedDuration = estimatedDuration;
 }