Class RepositoryService
java.lang.Object
edu.ucsb.cs156.frontiers.services.RepositoryService
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordstatic final recordResult of a create-repository call: the repository name and whether the repository was newly created (true) or already existed and was potentially updated (false). -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe name of the ruleset that requires signed commits on a repository. -
Constructor Summary
ConstructorsConstructorDescriptionRepositoryService(JwtService jwtService, GithubTeamService githubTeamService, TeamRepository teamRepository, org.springframework.boot.web.client.RestTemplateBuilder restTemplateBuilder, com.fasterxml.jackson.databind.ObjectMapper mapper) -
Method Summary
Modifier and TypeMethodDescriptioncreateStaffRepository(Course course, CourseStaff staff, String repoPrefix, Boolean isPrivate, RepositoryPermissions permissions) Creates a single staff repository if it doesn't already exist, and provisions access to the repository by that staff membercreateStudentRepository(Course course, RosterStudent student, String repoPrefix, Boolean isPrivate, RepositoryPermissions permissions) Creates a single student repository if it doesn't already exist, and provisions access to the repository by that studentcreateTeamRepository(Course course, Team team, String repoPrefix, Boolean isPrivate, RepositoryPermissions permissions, Integer orgId) Creates a GitHub repository for a team (student or staff), given only their team name.booleandeleteRepositoryIfEmpty(Course course, String repositoryName) Deletes a repository only when it is empty.getRepositoriesMatchingPrefix(Course course, String prefix) Lists repositories in the course GitHub organization whose names start with the provided prefix.booleanisRepositoryEmpty(Course course, String repositoryName) Returns true when the repository has no commits.voidsetSignedCommitsRequired(Course course, String repositoryName, boolean required) Makes a repository require signed commits, or not, by giving it a ruleset named "Require Signed Commits", or removing that ruleset.
-
Field Details
-
SIGNED_COMMITS_RULESET_NAME
The name of the ruleset that requires signed commits on a repository.- See Also:
-
-
Constructor Details
-
RepositoryService
public RepositoryService(JwtService jwtService, GithubTeamService githubTeamService, TeamRepository teamRepository, org.springframework.boot.web.client.RestTemplateBuilder restTemplateBuilder, com.fasterxml.jackson.databind.ObjectMapper mapper)
-
-
Method Details
-
createStudentRepository
public Optional<RepositoryService.RepositoryCreationResult> createStudentRepository(Course course, RosterStudent student, String repoPrefix, Boolean isPrivate, RepositoryPermissions permissions) throws NoSuchAlgorithmException, InvalidKeySpecException, com.fasterxml.jackson.core.JsonProcessingException Creates a single student repository if it doesn't already exist, and provisions access to the repository by that student- Parameters:
course- The Course in questionstudent- RosterStudent of the student the repository should be created forrepoPrefix- Name of the project or assignment. Used to title the repository, in the format repoPrefix-githubLoginisPrivate- Whether the repository is private or not- Returns:
- a
RepositoryService.RepositoryCreationResultindicating the repository name and whether it was newly created, orOptional.empty()if the existence check failed unexpectedly - Throws:
NoSuchAlgorithmExceptionInvalidKeySpecExceptioncom.fasterxml.jackson.core.JsonProcessingException
-
createStaffRepository
public Optional<RepositoryService.RepositoryCreationResult> createStaffRepository(Course course, CourseStaff staff, String repoPrefix, Boolean isPrivate, RepositoryPermissions permissions) throws NoSuchAlgorithmException, InvalidKeySpecException, com.fasterxml.jackson.core.JsonProcessingException Creates a single staff repository if it doesn't already exist, and provisions access to the repository by that staff member- Parameters:
course- The Course in questionstaff- CourseStaff of the staff the repository should be created forrepoPrefix- Name of the project or assignment. Used to title the repository, in the format repoPrefix-githubLoginisPrivate- Whether the repository is private or not- Returns:
- a
RepositoryService.RepositoryCreationResultindicating the repository name and whether it was newly created, orOptional.empty()if the existence check failed unexpectedly - Throws:
NoSuchAlgorithmExceptionInvalidKeySpecExceptioncom.fasterxml.jackson.core.JsonProcessingException
-
setSignedCommitsRequired
public void setSignedCommitsRequired(Course course, String repositoryName, boolean required) throws NoSuchAlgorithmException, InvalidKeySpecException, com.fasterxml.jackson.core.JsonProcessingException Makes a repository require signed commits, or not, by giving it a ruleset named "Require Signed Commits", or removing that ruleset. The ruleset requires signatures on every branch except gh-pages, and is active.- required, and the repository has no such ruleset: it is created.
- required, and the repository already has it: it is updated in place, so that it has the settings above and the repository is never without it.
- not required, and the repository has it: it is deleted.
- not required, and it does not: nothing is changed.
- Parameters:
course- the course whose organization the repository belongs torepositoryName- the name of the repositoryrequired- whether commits must be signed- Throws:
org.springframework.web.client.HttpStatusCodeException- if GitHub refuses a request, for example because the GitHub App is not allowed to administer repositoriesNoSuchAlgorithmExceptionInvalidKeySpecExceptioncom.fasterxml.jackson.core.JsonProcessingException
-
getRepositoriesMatchingPrefix
public List<RepositoryService.GithubRepository> getRepositoriesMatchingPrefix(Course course, String prefix) throws NoSuchAlgorithmException, InvalidKeySpecException, com.fasterxml.jackson.core.JsonProcessingException Lists repositories in the course GitHub organization whose names start with the provided prefix.- Throws:
NoSuchAlgorithmExceptionInvalidKeySpecExceptioncom.fasterxml.jackson.core.JsonProcessingException
-
isRepositoryEmpty
public boolean isRepositoryEmpty(Course course, String repositoryName) throws NoSuchAlgorithmException, InvalidKeySpecException, com.fasterxml.jackson.core.JsonProcessingException Returns true when the repository has no commits.- Throws:
NoSuchAlgorithmExceptionInvalidKeySpecExceptioncom.fasterxml.jackson.core.JsonProcessingException
-
deleteRepositoryIfEmpty
public boolean deleteRepositoryIfEmpty(Course course, String repositoryName) throws NoSuchAlgorithmException, InvalidKeySpecException, com.fasterxml.jackson.core.JsonProcessingException Deletes a repository only when it is empty. Returns true when a delete request was sent.- Throws:
NoSuchAlgorithmExceptionInvalidKeySpecExceptioncom.fasterxml.jackson.core.JsonProcessingException
-
createTeamRepository
public Optional<RepositoryService.RepositoryCreationResult> createTeamRepository(Course course, Team team, String repoPrefix, Boolean isPrivate, RepositoryPermissions permissions, Integer orgId) throws NoSuchAlgorithmException, InvalidKeySpecException, com.fasterxml.jackson.core.JsonProcessingException Creates a GitHub repository for a team (student or staff), given only their team name.- Checks whether the repository already exists.
- If not, creates a new repository under the course's organization; if so, makes it private or public as given, since that may have changed since it was created.
- Adds all team members as collaborators with the given permission level.
- Parameters:
course- the course whose organization the repo belongs toteam- the team for which the repo is being createdrepoPrefix- prefix for the repository name (repoPrefix-teamSlug)isPrivate- whether the created repository should be privatepermissions- collaborator permissions to grant the userorgId- GitHub organization ID used for team-based repo provisioning- Returns:
- a
RepositoryService.RepositoryCreationResultindicating the repository name and whether it was newly created, orOptional.empty()if the existence check failed unexpectedly - Throws:
NoSuchAlgorithmException- if signing failsInvalidKeySpecException- if signing failscom.fasterxml.jackson.core.JsonProcessingException- if JSON serialization fails
-