diff --git a/src/main/resources/update/2_9.sql b/src/main/resources/update/2_9.sql index 1ac303b..3ddc48a 100644 --- a/src/main/resources/update/2_9.sql +++ b/src/main/resources/update/2_9.sql @@ -1,42 +1,42 @@ -DROP TABLE IF EXISTS ACCESS_TOKEN; - -CREATE TABLE ACCESS_TOKEN ( - ACCESS_TOKEN_ID INT NOT NULL AUTO_INCREMENT, - TOKEN_HASH VARCHAR(40) NOT NULL, - USER_NAME VARCHAR(100) NOT NULL, - NOTE TEXT NOT NULL -); - -ALTER TABLE ACCESS_TOKEN ADD CONSTRAINT IDX_ACCESS_TOKEN_PK PRIMARY KEY (ACCESS_TOKEN_ID); -ALTER TABLE ACCESS_TOKEN ADD CONSTRAINT IDX_ACCESS_TOKEN_FK0 FOREIGN KEY (USER_NAME) REFERENCES ACCOUNT (USER_NAME) - ON DELETE CASCADE ON UPDATE CASCADE; -ALTER TABLE ACCESS_TOKEN ADD CONSTRAINT IDX_ACCESS_TOKEN_TOKEN_HASH UNIQUE(TOKEN_HASH); - - -DROP TABLE IF EXISTS COMMIT_STATUS; -CREATE TABLE COMMIT_STATUS( - COMMIT_STATUS_ID INT AUTO_INCREMENT, - USER_NAME VARCHAR(100) NOT NULL, - REPOSITORY_NAME VARCHAR(100) NOT NULL, - COMMIT_ID VARCHAR(40) NOT NULL, - CONTEXT VARCHAR(255) NOT NULL, -- context is too long (maximum is 255 characters) - STATE VARCHAR(10) NOT NULL, -- pending, success, error, or failure - TARGET_URL VARCHAR(200), - DESCRIPTION TEXT, - CREATOR VARCHAR(100) NOT NULL, - REGISTERED_DATE TIMESTAMP NOT NULL, -- CREATED_AT - UPDATED_DATE TIMESTAMP NOT NULL -- UPDATED_AT -); -ALTER TABLE COMMIT_STATUS ADD CONSTRAINT IDX_COMMIT_STATUS_PK PRIMARY KEY (COMMIT_STATUS_ID); -ALTER TABLE COMMIT_STATUS ADD CONSTRAINT IDX_COMMIT_STATUS_1 - UNIQUE (USER_NAME, REPOSITORY_NAME, COMMIT_ID, CONTEXT); -ALTER TABLE COMMIT_STATUS ADD CONSTRAINT IDX_COMMIT_STATUS_FK1 - FOREIGN KEY (USER_NAME, REPOSITORY_NAME) - REFERENCES REPOSITORY (USER_NAME, REPOSITORY_NAME) - ON DELETE CASCADE ON UPDATE CASCADE; -ALTER TABLE COMMIT_STATUS ADD CONSTRAINT IDX_COMMIT_STATUS_FK2 - FOREIGN KEY (USER_NAME) REFERENCES ACCOUNT (USER_NAME) - ON DELETE CASCADE ON UPDATE CASCADE; -ALTER TABLE COMMIT_STATUS ADD CONSTRAINT IDX_COMMIT_STATUS_FK3 - FOREIGN KEY (CREATOR) REFERENCES ACCOUNT (USER_NAME) - ON DELETE CASCADE ON UPDATE CASCADE; +DROP TABLE IF EXISTS ACCESS_TOKEN; + +CREATE TABLE ACCESS_TOKEN ( + ACCESS_TOKEN_ID INT NOT NULL AUTO_INCREMENT, + TOKEN_HASH VARCHAR(40) NOT NULL, + USER_NAME VARCHAR(100) NOT NULL, + NOTE TEXT NOT NULL +); + +ALTER TABLE ACCESS_TOKEN ADD CONSTRAINT IDX_ACCESS_TOKEN_PK PRIMARY KEY (ACCESS_TOKEN_ID); +ALTER TABLE ACCESS_TOKEN ADD CONSTRAINT IDX_ACCESS_TOKEN_FK0 FOREIGN KEY (USER_NAME) REFERENCES ACCOUNT (USER_NAME) + ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE ACCESS_TOKEN ADD CONSTRAINT IDX_ACCESS_TOKEN_TOKEN_HASH UNIQUE(TOKEN_HASH); + + +DROP TABLE IF EXISTS COMMIT_STATUS; +CREATE TABLE COMMIT_STATUS( + COMMIT_STATUS_ID INT AUTO_INCREMENT, + USER_NAME VARCHAR(100) NOT NULL, + REPOSITORY_NAME VARCHAR(100) NOT NULL, + COMMIT_ID VARCHAR(40) NOT NULL, + CONTEXT VARCHAR(255) NOT NULL, -- context is too long (maximum is 255 characters) + STATE VARCHAR(10) NOT NULL, -- pending, success, error, or failure + TARGET_URL VARCHAR(200), + DESCRIPTION TEXT, + CREATOR VARCHAR(100) NOT NULL, + REGISTERED_DATE TIMESTAMP NOT NULL, -- CREATED_AT + UPDATED_DATE TIMESTAMP NOT NULL -- UPDATED_AT +); +ALTER TABLE COMMIT_STATUS ADD CONSTRAINT IDX_COMMIT_STATUS_PK PRIMARY KEY (COMMIT_STATUS_ID); +ALTER TABLE COMMIT_STATUS ADD CONSTRAINT IDX_COMMIT_STATUS_1 + UNIQUE (USER_NAME, REPOSITORY_NAME, COMMIT_ID, CONTEXT); +ALTER TABLE COMMIT_STATUS ADD CONSTRAINT IDX_COMMIT_STATUS_FK1 + FOREIGN KEY (USER_NAME, REPOSITORY_NAME) + REFERENCES REPOSITORY (USER_NAME, REPOSITORY_NAME) + ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE COMMIT_STATUS ADD CONSTRAINT IDX_COMMIT_STATUS_FK2 + FOREIGN KEY (USER_NAME) REFERENCES ACCOUNT (USER_NAME) + ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE COMMIT_STATUS ADD CONSTRAINT IDX_COMMIT_STATUS_FK3 + FOREIGN KEY (CREATOR) REFERENCES ACCOUNT (USER_NAME) + ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/src/main/scala/api/ApiCombinedCommitStatus.scala b/src/main/scala/api/ApiCombinedCommitStatus.scala index 29d8fa7..19f2ead 100644 --- a/src/main/scala/api/ApiCombinedCommitStatus.scala +++ b/src/main/scala/api/ApiCombinedCommitStatus.scala @@ -1,26 +1,26 @@ -package api - -import model.Account -import model.CommitStatus -import model.CommitState - -/** - * https://developer.github.com/v3/repos/statuses/#get-the-combined-status-for-a-specific-ref - */ -case class ApiCombinedCommitStatus( - state: String, - sha: String, - total_count: Int, - statuses: Iterable[ApiCommitStatus], - repository: ApiRepository){ - // val commit_url = ApiPath(s"/api/v3/repos/${repository.full_name}/${sha}") - val url = ApiPath(s"/api/v3/repos/${repository.full_name}/commits/${sha}/status") -} -object ApiCombinedCommitStatus { - def apply(sha:String, statuses: Iterable[(CommitStatus, Account)], repository:ApiRepository): ApiCombinedCommitStatus = ApiCombinedCommitStatus( - state = CommitState.combine(statuses.map(_._1.state).toSet).name, - sha = sha, - total_count= statuses.size, - statuses = statuses.map{ case (s, a)=> ApiCommitStatus(s, ApiUser(a)) }, - repository = repository) -} +package api + +import model.Account +import model.CommitStatus +import model.CommitState + +/** + * https://developer.github.com/v3/repos/statuses/#get-the-combined-status-for-a-specific-ref + */ +case class ApiCombinedCommitStatus( + state: String, + sha: String, + total_count: Int, + statuses: Iterable[ApiCommitStatus], + repository: ApiRepository){ + // val commit_url = ApiPath(s"/api/v3/repos/${repository.full_name}/${sha}") + val url = ApiPath(s"/api/v3/repos/${repository.full_name}/commits/${sha}/status") +} +object ApiCombinedCommitStatus { + def apply(sha:String, statuses: Iterable[(CommitStatus, Account)], repository:ApiRepository): ApiCombinedCommitStatus = ApiCombinedCommitStatus( + state = CommitState.combine(statuses.map(_._1.state).toSet).name, + sha = sha, + total_count= statuses.size, + statuses = statuses.map{ case (s, a)=> ApiCommitStatus(s, ApiUser(a)) }, + repository = repository) +} diff --git a/src/main/scala/api/ApiComment.scala b/src/main/scala/api/ApiComment.scala index 1733fb3..34197f0 100644 --- a/src/main/scala/api/ApiComment.scala +++ b/src/main/scala/api/ApiComment.scala @@ -1,24 +1,24 @@ -package api - -import java.util.Date -import model.IssueComment - -/** - * https://developer.github.com/v3/issues/comments/ - */ -case class ApiComment( - id: Int, - user: ApiUser, - body: String, - created_at: Date, - updated_at: Date) - -object ApiComment{ - def apply(comment: IssueComment, user: ApiUser): ApiComment = - ApiComment( - id = comment.commentId, - user = user, - body = comment.content, - created_at = comment.registeredDate, - updated_at = comment.updatedDate) -} +package api + +import java.util.Date +import model.IssueComment + +/** + * https://developer.github.com/v3/issues/comments/ + */ +case class ApiComment( + id: Int, + user: ApiUser, + body: String, + created_at: Date, + updated_at: Date) + +object ApiComment{ + def apply(comment: IssueComment, user: ApiUser): ApiComment = + ApiComment( + id = comment.commentId, + user = user, + body = comment.content, + created_at = comment.registeredDate, + updated_at = comment.updatedDate) +} diff --git a/src/main/scala/api/ApiCommit.scala b/src/main/scala/api/ApiCommit.scala index f4ef17a..57ee02d 100644 --- a/src/main/scala/api/ApiCommit.scala +++ b/src/main/scala/api/ApiCommit.scala @@ -1,41 +1,41 @@ -package api - -import java.util.Date -import org.eclipse.jgit.diff.DiffEntry -import util.JGitUtil -import util.JGitUtil.CommitInfo -import org.eclipse.jgit.api.Git -import util.RepositoryName - -/** - * https://developer.github.com/v3/repos/commits/ - */ -case class ApiCommit( - id: String, - message: String, - timestamp: Date, - added: List[String], - removed: List[String], - modified: List[String], - author: ApiPersonIdent, - committer: ApiPersonIdent)(repositoryName:RepositoryName){ - val url = ApiPath(s"/api/v3/${repositoryName.fullName}/commits/${id}") - val html_url = ApiPath(s"/${repositoryName.fullName}/commit/${id}") -} - -object ApiCommit{ - def apply(git: Git, repositoryName: RepositoryName, commit: CommitInfo): ApiCommit = { - val diffs = JGitUtil.getDiffs(git, commit.id, false) - ApiCommit( - id = commit.id, - message = commit.fullMessage, - timestamp = commit.commitTime, - added = diffs._1.collect { case x if(x.changeType == DiffEntry.ChangeType.ADD) => x.newPath }, - removed = diffs._1.collect { case x if(x.changeType == DiffEntry.ChangeType.DELETE) => x.oldPath }, - modified = diffs._1.collect { case x if(x.changeType != DiffEntry.ChangeType.ADD && - x.changeType != DiffEntry.ChangeType.DELETE) => x.newPath }, - author = ApiPersonIdent.author(commit), - committer = ApiPersonIdent.committer(commit) - )(repositoryName) - } -} +package api + +import java.util.Date +import org.eclipse.jgit.diff.DiffEntry +import util.JGitUtil +import util.JGitUtil.CommitInfo +import org.eclipse.jgit.api.Git +import util.RepositoryName + +/** + * https://developer.github.com/v3/repos/commits/ + */ +case class ApiCommit( + id: String, + message: String, + timestamp: Date, + added: List[String], + removed: List[String], + modified: List[String], + author: ApiPersonIdent, + committer: ApiPersonIdent)(repositoryName:RepositoryName){ + val url = ApiPath(s"/api/v3/${repositoryName.fullName}/commits/${id}") + val html_url = ApiPath(s"/${repositoryName.fullName}/commit/${id}") +} + +object ApiCommit{ + def apply(git: Git, repositoryName: RepositoryName, commit: CommitInfo): ApiCommit = { + val diffs = JGitUtil.getDiffs(git, commit.id, false) + ApiCommit( + id = commit.id, + message = commit.fullMessage, + timestamp = commit.commitTime, + added = diffs._1.collect { case x if(x.changeType == DiffEntry.ChangeType.ADD) => x.newPath }, + removed = diffs._1.collect { case x if(x.changeType == DiffEntry.ChangeType.DELETE) => x.oldPath }, + modified = diffs._1.collect { case x if(x.changeType != DiffEntry.ChangeType.ADD && + x.changeType != DiffEntry.ChangeType.DELETE) => x.newPath }, + author = ApiPersonIdent.author(commit), + committer = ApiPersonIdent.committer(commit) + )(repositoryName) + } +} diff --git a/src/main/scala/api/ApiCommitListItem.scala b/src/main/scala/api/ApiCommitListItem.scala index c345661..4a80d8c 100644 --- a/src/main/scala/api/ApiCommitListItem.scala +++ b/src/main/scala/api/ApiCommitListItem.scala @@ -1,41 +1,41 @@ -package api - -import util.JGitUtil.CommitInfo -import ApiCommitListItem._ -import util.RepositoryName - -/** - * https://developer.github.com/v3/repos/commits/ - */ -case class ApiCommitListItem( - sha: String, - commit: Commit, - author: Option[ApiUser], - committer: Option[ApiUser], - parents: Seq[Parent])(repositoryName: RepositoryName) { - val url = ApiPath(s"/api/v3/repos/${repositoryName.fullName}/commits/${sha}") -} - -object ApiCommitListItem { - def apply(commit: CommitInfo, repositoryName: RepositoryName): ApiCommitListItem = ApiCommitListItem( - sha = commit.id, - commit = Commit( - message = commit.fullMessage, - author = ApiPersonIdent.author(commit), - committer = ApiPersonIdent.committer(commit) - )(commit.id, repositoryName), - author = None, - committer = None, - parents = commit.parents.map(Parent(_)(repositoryName)))(repositoryName) - - case class Parent(sha: String)(repositoryName: RepositoryName){ - val url = ApiPath(s"/api/v3/repos/${repositoryName.fullName}/commits/${sha}") - } - - case class Commit( - message: String, - author: ApiPersonIdent, - committer: ApiPersonIdent)(sha:String, repositoryName: RepositoryName) { - val url = ApiPath(s"/api/v3/repos/${repositoryName.fullName}/git/commits/${sha}") - } -} +package api + +import util.JGitUtil.CommitInfo +import ApiCommitListItem._ +import util.RepositoryName + +/** + * https://developer.github.com/v3/repos/commits/ + */ +case class ApiCommitListItem( + sha: String, + commit: Commit, + author: Option[ApiUser], + committer: Option[ApiUser], + parents: Seq[Parent])(repositoryName: RepositoryName) { + val url = ApiPath(s"/api/v3/repos/${repositoryName.fullName}/commits/${sha}") +} + +object ApiCommitListItem { + def apply(commit: CommitInfo, repositoryName: RepositoryName): ApiCommitListItem = ApiCommitListItem( + sha = commit.id, + commit = Commit( + message = commit.fullMessage, + author = ApiPersonIdent.author(commit), + committer = ApiPersonIdent.committer(commit) + )(commit.id, repositoryName), + author = None, + committer = None, + parents = commit.parents.map(Parent(_)(repositoryName)))(repositoryName) + + case class Parent(sha: String)(repositoryName: RepositoryName){ + val url = ApiPath(s"/api/v3/repos/${repositoryName.fullName}/commits/${sha}") + } + + case class Commit( + message: String, + author: ApiPersonIdent, + committer: ApiPersonIdent)(sha:String, repositoryName: RepositoryName) { + val url = ApiPath(s"/api/v3/repos/${repositoryName.fullName}/git/commits/${sha}") + } +} diff --git a/src/main/scala/api/ApiCommitStatus.scala b/src/main/scala/api/ApiCommitStatus.scala index e6e2ea1..011be26 100644 --- a/src/main/scala/api/ApiCommitStatus.scala +++ b/src/main/scala/api/ApiCommitStatus.scala @@ -1,35 +1,35 @@ -package api - -import java.util.Date -import model.CommitStatus -import util.RepositoryName - -/** - * https://developer.github.com/v3/repos/statuses/#create-a-status - * https://developer.github.com/v3/repos/statuses/#list-statuses-for-a-specific-ref - */ -case class ApiCommitStatus( - created_at: Date, - updated_at: Date, - state: String, - target_url: Option[String], - description: Option[String], - id: Int, - context: String, - creator: ApiUser -)(sha: String,repositoryName: RepositoryName) { - val url = ApiPath(s"/api/v3/repos/${repositoryName.fullName}/commits/${sha}/statuses") -} - -object ApiCommitStatus { - def apply(status: CommitStatus, creator:ApiUser): ApiCommitStatus = ApiCommitStatus( - created_at = status.registeredDate, - updated_at = status.updatedDate, - state = status.state.name, - target_url = status.targetUrl, - description= status.description, - id = status.commitStatusId, - context = status.context, - creator = creator - )(status.commitId, RepositoryName(status)) -} +package api + +import java.util.Date +import model.CommitStatus +import util.RepositoryName + +/** + * https://developer.github.com/v3/repos/statuses/#create-a-status + * https://developer.github.com/v3/repos/statuses/#list-statuses-for-a-specific-ref + */ +case class ApiCommitStatus( + created_at: Date, + updated_at: Date, + state: String, + target_url: Option[String], + description: Option[String], + id: Int, + context: String, + creator: ApiUser +)(sha: String,repositoryName: RepositoryName) { + val url = ApiPath(s"/api/v3/repos/${repositoryName.fullName}/commits/${sha}/statuses") +} + +object ApiCommitStatus { + def apply(status: CommitStatus, creator:ApiUser): ApiCommitStatus = ApiCommitStatus( + created_at = status.registeredDate, + updated_at = status.updatedDate, + state = status.state.name, + target_url = status.targetUrl, + description= status.description, + id = status.commitStatusId, + context = status.context, + creator = creator + )(status.commitId, RepositoryName(status)) +} diff --git a/src/main/scala/api/ApiError.scala b/src/main/scala/api/ApiError.scala index d0470dc..8acdba2 100644 --- a/src/main/scala/api/ApiError.scala +++ b/src/main/scala/api/ApiError.scala @@ -1,5 +1,5 @@ -package api - -case class ApiError( - message: String, - documentation_url: Option[String] = None) +package api + +case class ApiError( + message: String, + documentation_url: Option[String] = None) diff --git a/src/main/scala/api/ApiIssue.scala b/src/main/scala/api/ApiIssue.scala index 6c31d6a..1bbb55a 100644 --- a/src/main/scala/api/ApiIssue.scala +++ b/src/main/scala/api/ApiIssue.scala @@ -1,29 +1,29 @@ -package api - -import java.util.Date -import model.Issue - -/** - * https://developer.github.com/v3/issues/ - */ -case class ApiIssue( - number: Int, - title: String, - user: ApiUser, - // labels, - state: String, - created_at: Date, - updated_at: Date, - body: String) - -object ApiIssue{ - def apply(issue: Issue, user: ApiUser): ApiIssue = - ApiIssue( - number = issue.issueId, - title = issue.title, - user = user, - state = if(issue.closed){ "closed" }else{ "open" }, - body = issue.content.getOrElse(""), - created_at = issue.registeredDate, - updated_at = issue.updatedDate) -} +package api + +import java.util.Date +import model.Issue + +/** + * https://developer.github.com/v3/issues/ + */ +case class ApiIssue( + number: Int, + title: String, + user: ApiUser, + // labels, + state: String, + created_at: Date, + updated_at: Date, + body: String) + +object ApiIssue{ + def apply(issue: Issue, user: ApiUser): ApiIssue = + ApiIssue( + number = issue.issueId, + title = issue.title, + user = user, + state = if(issue.closed){ "closed" }else{ "open" }, + body = issue.content.getOrElse(""), + created_at = issue.registeredDate, + updated_at = issue.updatedDate) +} diff --git a/src/main/scala/api/ApiPath.scala b/src/main/scala/api/ApiPath.scala index 2572945..1f6701e 100644 --- a/src/main/scala/api/ApiPath.scala +++ b/src/main/scala/api/ApiPath.scala @@ -1,6 +1,6 @@ -package api - -/** - * path for api url. if set path '/repos/aa/bb' then, expand 'http://server:post/repos/aa/bb' when converted to json. - */ -case class ApiPath(path: String) +package api + +/** + * path for api url. if set path '/repos/aa/bb' then, expand 'http://server:post/repos/aa/bb' when converted to json. + */ +case class ApiPath(path: String) diff --git a/src/main/scala/api/ApiPersonIdent.scala b/src/main/scala/api/ApiPersonIdent.scala index c9b3b97..010f539 100644 --- a/src/main/scala/api/ApiPersonIdent.scala +++ b/src/main/scala/api/ApiPersonIdent.scala @@ -1,22 +1,22 @@ -package api - -import java.util.Date -import util.JGitUtil.CommitInfo - -case class ApiPersonIdent( - name: String, - email: String, - date: Date) - -object ApiPersonIdent { - def author(commit: CommitInfo): ApiPersonIdent = - ApiPersonIdent( - name = commit.authorName, - email = commit.authorEmailAddress, - date = commit.authorTime) - def committer(commit: CommitInfo): ApiPersonIdent = - ApiPersonIdent( - name = commit.committerName, - email = commit.committerEmailAddress, - date = commit.commitTime) -} +package api + +import java.util.Date +import util.JGitUtil.CommitInfo + +case class ApiPersonIdent( + name: String, + email: String, + date: Date) + +object ApiPersonIdent { + def author(commit: CommitInfo): ApiPersonIdent = + ApiPersonIdent( + name = commit.authorName, + email = commit.authorEmailAddress, + date = commit.authorTime) + def committer(commit: CommitInfo): ApiPersonIdent = + ApiPersonIdent( + name = commit.committerName, + email = commit.committerEmailAddress, + date = commit.commitTime) +} diff --git a/src/main/scala/api/ApiPullRequest.scala b/src/main/scala/api/ApiPullRequest.scala index 975f562..7ce6f6d 100644 --- a/src/main/scala/api/ApiPullRequest.scala +++ b/src/main/scala/api/ApiPullRequest.scala @@ -1,58 +1,58 @@ -package api - -import java.util.Date -import model.{Issue, PullRequest} -import ApiPullRequest._ - -/** - * https://developer.github.com/v3/pulls/ - */ -case class ApiPullRequest( - number: Int, - updated_at: Date, - created_at: Date, - head: ApiPullRequest.Commit, - base: ApiPullRequest.Commit, - mergeable: Option[Boolean], - title: String, - body: String, - user: ApiUser) { - val html_url = ApiPath(s"${base.repo.html_url.path}/pull/${number}") - //val diff_url = ApiPath(s"${base.repo.html_url.path}/pull/${number}.diff") - //val patch_url = ApiPath(s"${base.repo.html_url.path}/pull/${number}.patch") - val url = ApiPath(s"${base.repo.url.path}/pulls/${number}") - //val issue_url = ApiPath(s"${base.repo.url.path}/issues/${number}") - val commits_url = ApiPath(s"${base.repo.url.path}/pulls/${number}/commits") - val review_comments_url = ApiPath(s"${base.repo.url.path}/pulls/${number}/comments") - val review_comment_url = ApiPath(s"${base.repo.url.path}/pulls/comments/{number}") - val comments_url = ApiPath(s"${base.repo.url.path}/issues/${number}/comments") - val statuses_url = ApiPath(s"${base.repo.url.path}/statuses/${head.sha}") -} - -object ApiPullRequest{ - def apply(issue: Issue, pullRequest: PullRequest, headRepo: ApiRepository, baseRepo: ApiRepository, user: ApiUser): ApiPullRequest = ApiPullRequest( - number = issue.issueId, - updated_at = issue.updatedDate, - created_at = issue.registeredDate, - head = Commit( - sha = pullRequest.commitIdTo, - ref = pullRequest.requestBranch, - repo = headRepo)(issue.userName), - base = Commit( - sha = pullRequest.commitIdFrom, - ref = pullRequest.branch, - repo = baseRepo)(issue.userName), - mergeable = None, // TODO: need check mergeable. - title = issue.title, - body = issue.content.getOrElse(""), - user = user - ) - - case class Commit( - sha: String, - ref: String, - repo: ApiRepository)(baseOwner:String){ - val label = if( baseOwner == repo.owner.login ){ ref }else{ s"${repo.owner.login}:${ref}" } - val user = repo.owner - } -} +package api + +import java.util.Date +import model.{Issue, PullRequest} +import ApiPullRequest._ + +/** + * https://developer.github.com/v3/pulls/ + */ +case class ApiPullRequest( + number: Int, + updated_at: Date, + created_at: Date, + head: ApiPullRequest.Commit, + base: ApiPullRequest.Commit, + mergeable: Option[Boolean], + title: String, + body: String, + user: ApiUser) { + val html_url = ApiPath(s"${base.repo.html_url.path}/pull/${number}") + //val diff_url = ApiPath(s"${base.repo.html_url.path}/pull/${number}.diff") + //val patch_url = ApiPath(s"${base.repo.html_url.path}/pull/${number}.patch") + val url = ApiPath(s"${base.repo.url.path}/pulls/${number}") + //val issue_url = ApiPath(s"${base.repo.url.path}/issues/${number}") + val commits_url = ApiPath(s"${base.repo.url.path}/pulls/${number}/commits") + val review_comments_url = ApiPath(s"${base.repo.url.path}/pulls/${number}/comments") + val review_comment_url = ApiPath(s"${base.repo.url.path}/pulls/comments/{number}") + val comments_url = ApiPath(s"${base.repo.url.path}/issues/${number}/comments") + val statuses_url = ApiPath(s"${base.repo.url.path}/statuses/${head.sha}") +} + +object ApiPullRequest{ + def apply(issue: Issue, pullRequest: PullRequest, headRepo: ApiRepository, baseRepo: ApiRepository, user: ApiUser): ApiPullRequest = ApiPullRequest( + number = issue.issueId, + updated_at = issue.updatedDate, + created_at = issue.registeredDate, + head = Commit( + sha = pullRequest.commitIdTo, + ref = pullRequest.requestBranch, + repo = headRepo)(issue.userName), + base = Commit( + sha = pullRequest.commitIdFrom, + ref = pullRequest.branch, + repo = baseRepo)(issue.userName), + mergeable = None, // TODO: need check mergeable. + title = issue.title, + body = issue.content.getOrElse(""), + user = user + ) + + case class Commit( + sha: String, + ref: String, + repo: ApiRepository)(baseOwner:String){ + val label = if( baseOwner == repo.owner.login ){ ref }else{ s"${repo.owner.login}:${ref}" } + val user = repo.owner + } +} diff --git a/src/main/scala/api/ApiRepository.scala b/src/main/scala/api/ApiRepository.scala index 05949b8..1962e47 100644 --- a/src/main/scala/api/ApiRepository.scala +++ b/src/main/scala/api/ApiRepository.scala @@ -1,48 +1,48 @@ -package api - -import util.JGitUtil.CommitInfo -import service.RepositoryService.RepositoryInfo -import model.{Account, Repository} - -// https://developer.github.com/v3/repos/ -case class ApiRepository( - name: String, - full_name: String, - description: String, - watchers: Int, - forks: Int, - `private`: Boolean, - default_branch: String, - owner: ApiUser) { - val forks_count = forks - val watchers_coun = watchers - val url = ApiPath(s"/api/v3/repos/${full_name}") - val http_url = ApiPath(s"/git/${full_name}.git") - val clone_url = ApiPath(s"/git/${full_name}.git") - val html_url = ApiPath(s"/${full_name}") -} - -object ApiRepository{ - def apply( - repository: Repository, - owner: ApiUser, - forkedCount: Int =0, - watchers: Int = 0): ApiRepository = - ApiRepository( - name = repository.repositoryName, - full_name = s"${repository.userName}/${repository.repositoryName}", - description = repository.description.getOrElse(""), - watchers = 0, - forks = forkedCount, - `private` = repository.isPrivate, - default_branch = repository.defaultBranch, - owner = owner - ) - - def apply(repositoryInfo: RepositoryInfo, owner: ApiUser): ApiRepository = - ApiRepository(repositoryInfo.repository, owner, forkedCount=repositoryInfo.forkedCount) - - def apply(repositoryInfo: RepositoryInfo, owner: Account): ApiRepository = - this(repositoryInfo.repository, ApiUser(owner)) - -} +package api + +import util.JGitUtil.CommitInfo +import service.RepositoryService.RepositoryInfo +import model.{Account, Repository} + +// https://developer.github.com/v3/repos/ +case class ApiRepository( + name: String, + full_name: String, + description: String, + watchers: Int, + forks: Int, + `private`: Boolean, + default_branch: String, + owner: ApiUser) { + val forks_count = forks + val watchers_coun = watchers + val url = ApiPath(s"/api/v3/repos/${full_name}") + val http_url = ApiPath(s"/git/${full_name}.git") + val clone_url = ApiPath(s"/git/${full_name}.git") + val html_url = ApiPath(s"/${full_name}") +} + +object ApiRepository{ + def apply( + repository: Repository, + owner: ApiUser, + forkedCount: Int =0, + watchers: Int = 0): ApiRepository = + ApiRepository( + name = repository.repositoryName, + full_name = s"${repository.userName}/${repository.repositoryName}", + description = repository.description.getOrElse(""), + watchers = 0, + forks = forkedCount, + `private` = repository.isPrivate, + default_branch = repository.defaultBranch, + owner = owner + ) + + def apply(repositoryInfo: RepositoryInfo, owner: ApiUser): ApiRepository = + ApiRepository(repositoryInfo.repository, owner, forkedCount=repositoryInfo.forkedCount) + + def apply(repositoryInfo: RepositoryInfo, owner: Account): ApiRepository = + this(repositoryInfo.repository, ApiUser(owner)) + +} diff --git a/src/main/scala/api/ApiUser.scala b/src/main/scala/api/ApiUser.scala index 5cbc326..f180a9d 100644 --- a/src/main/scala/api/ApiUser.scala +++ b/src/main/scala/api/ApiUser.scala @@ -1,33 +1,33 @@ -package api - -import java.util.Date -import model.Account - -case class ApiUser( - login: String, - email: String, - `type`: String, - site_admin: Boolean, - created_at: Date) { - val url = ApiPath(s"/api/v3/users/${login}") - val html_url = ApiPath(s"/${login}") - // val followers_url = ApiPath(s"/api/v3/users/${login}/followers") - // val following_url = ApiPath(s"/api/v3/users/${login}/following{/other_user}") - // val gists_url = ApiPath(s"/api/v3/users/${login}/gists{/gist_id}") - // val starred_url = ApiPath(s"/api/v3/users/${login}/starred{/owner}{/repo}") - // val subscriptions_url = ApiPath(s"/api/v3/users/${login}/subscriptions") - // val organizations_url = ApiPath(s"/api/v3/users/${login}/orgs") - // val repos_url = ApiPath(s"/api/v3/users/${login}/repos") - // val events_url = ApiPath(s"/api/v3/users/${login}/events{/privacy}") - // val received_events_url = ApiPath(s"/api/v3/users/${login}/received_events") -} - -object ApiUser{ - def apply(user: Account): ApiUser = ApiUser( - login = user.fullName, - email = user.mailAddress, - `type` = if(user.isGroupAccount){ "Organization" }else{ "User" }, - site_admin = user.isAdmin, - created_at = user.registeredDate - ) -} +package api + +import java.util.Date +import model.Account + +case class ApiUser( + login: String, + email: String, + `type`: String, + site_admin: Boolean, + created_at: Date) { + val url = ApiPath(s"/api/v3/users/${login}") + val html_url = ApiPath(s"/${login}") + // val followers_url = ApiPath(s"/api/v3/users/${login}/followers") + // val following_url = ApiPath(s"/api/v3/users/${login}/following{/other_user}") + // val gists_url = ApiPath(s"/api/v3/users/${login}/gists{/gist_id}") + // val starred_url = ApiPath(s"/api/v3/users/${login}/starred{/owner}{/repo}") + // val subscriptions_url = ApiPath(s"/api/v3/users/${login}/subscriptions") + // val organizations_url = ApiPath(s"/api/v3/users/${login}/orgs") + // val repos_url = ApiPath(s"/api/v3/users/${login}/repos") + // val events_url = ApiPath(s"/api/v3/users/${login}/events{/privacy}") + // val received_events_url = ApiPath(s"/api/v3/users/${login}/received_events") +} + +object ApiUser{ + def apply(user: Account): ApiUser = ApiUser( + login = user.fullName, + email = user.mailAddress, + `type` = if(user.isGroupAccount){ "Organization" }else{ "User" }, + site_admin = user.isAdmin, + created_at = user.registeredDate + ) +} diff --git a/src/main/scala/api/CreateAComment.scala b/src/main/scala/api/CreateAComment.scala index 733758d..138f705 100644 --- a/src/main/scala/api/CreateAComment.scala +++ b/src/main/scala/api/CreateAComment.scala @@ -1,7 +1,7 @@ -package api - -/** - * https://developer.github.com/v3/issues/comments/#create-a-comment - * api form - */ -case class CreateAComment(body: String) +package api + +/** + * https://developer.github.com/v3/issues/comments/#create-a-comment + * api form + */ +case class CreateAComment(body: String) diff --git a/src/main/scala/api/CreateAStatus.scala b/src/main/scala/api/CreateAStatus.scala index 5237cac..51b82a2 100644 --- a/src/main/scala/api/CreateAStatus.scala +++ b/src/main/scala/api/CreateAStatus.scala @@ -1,26 +1,26 @@ -package api - -import model.CommitState - -/** - * https://developer.github.com/v3/repos/statuses/#create-a-status - * api form - */ -case class CreateAStatus( - /* state is Required. The state of the status. Can be one of pending, success, error, or failure. */ - state: String, - /* context is a string label to differentiate this status from the status of other systems. Default: "default" */ - context: Option[String], - /* The target URL to associate with this status. This URL will be linked from the GitHub UI to allow users to easily see the ‘source’ of the Status. */ - target_url: Option[String], - /* description is a short description of the status.*/ - description: Option[String] -) { - def isValid: Boolean = { - CommitState.valueOf(state).isDefined && - // only http - target_url.filterNot(f => "\\Ahttps?://".r.findPrefixOf(f).isDefined && f.length<255).isEmpty && - context.filterNot(f => f.length<255).isEmpty && - description.filterNot(f => f.length<1000).isEmpty - } -} +package api + +import model.CommitState + +/** + * https://developer.github.com/v3/repos/statuses/#create-a-status + * api form + */ +case class CreateAStatus( + /* state is Required. The state of the status. Can be one of pending, success, error, or failure. */ + state: String, + /* context is a string label to differentiate this status from the status of other systems. Default: "default" */ + context: Option[String], + /* The target URL to associate with this status. This URL will be linked from the GitHub UI to allow users to easily see the ‘source’ of the Status. */ + target_url: Option[String], + /* description is a short description of the status.*/ + description: Option[String] +) { + def isValid: Boolean = { + CommitState.valueOf(state).isDefined && + // only http + target_url.filterNot(f => "\\Ahttps?://".r.findPrefixOf(f).isDefined && f.length<255).isEmpty && + context.filterNot(f => f.length<255).isEmpty && + description.filterNot(f => f.length<1000).isEmpty + } +} diff --git a/src/main/scala/api/JsonFormat.scala b/src/main/scala/api/JsonFormat.scala index f743534..385a24c 100644 --- a/src/main/scala/api/JsonFormat.scala +++ b/src/main/scala/api/JsonFormat.scala @@ -1,37 +1,37 @@ -package api -import org.json4s._ -import org.json4s.jackson.Serialization -import scala.util.Try -import org.joda.time.format._ -import org.joda.time.DateTime -import org.joda.time.DateTimeZone -import java.util.Date -object JsonFormat { - case class Context(baseUrl:String) - val parserISO = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss'Z'") - val jsonFormats = Serialization.formats(NoTypeHints) + new CustomSerializer[Date](format => - ( - { case JString(s) => Try(parserISO.parseDateTime(s)).toOption.map(_.toDate) - .getOrElse(throw new MappingException("Can't convert " + s + " to Date")) }, - { case x: Date => JString(parserISO.print(new DateTime(x).withZone(DateTimeZone.UTC))) } - ) - ) + FieldSerializer[ApiUser]() + FieldSerializer[ApiPullRequest]() + FieldSerializer[ApiRepository]() + - FieldSerializer[ApiCommitListItem.Parent]() + FieldSerializer[ApiCommitListItem]() + FieldSerializer[ApiCommitListItem.Commit]() + - FieldSerializer[ApiCommitStatus]() + FieldSerializer[ApiCommit]() + FieldSerializer[ApiCombinedCommitStatus]() + - FieldSerializer[ApiPullRequest.Commit]() - def apiPathSerializer(c: Context) = new CustomSerializer[ApiPath](format => - ( - { - case JString(s) if s.startsWith(c.baseUrl) => ApiPath(s.substring(c.baseUrl.length)) - case JString(s) => throw new MappingException("Can't convert " + s + " to ApiPath") - }, - { - case ApiPath(path) => JString(c.baseUrl+path) - } - ) - ) - /** - * convert object to json string - */ - def apply(obj: AnyRef)(implicit c: Context): String = Serialization.write(obj)(jsonFormats + apiPathSerializer(c)) -} +package api +import org.json4s._ +import org.json4s.jackson.Serialization +import scala.util.Try +import org.joda.time.format._ +import org.joda.time.DateTime +import org.joda.time.DateTimeZone +import java.util.Date +object JsonFormat { + case class Context(baseUrl:String) + val parserISO = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss'Z'") + val jsonFormats = Serialization.formats(NoTypeHints) + new CustomSerializer[Date](format => + ( + { case JString(s) => Try(parserISO.parseDateTime(s)).toOption.map(_.toDate) + .getOrElse(throw new MappingException("Can't convert " + s + " to Date")) }, + { case x: Date => JString(parserISO.print(new DateTime(x).withZone(DateTimeZone.UTC))) } + ) + ) + FieldSerializer[ApiUser]() + FieldSerializer[ApiPullRequest]() + FieldSerializer[ApiRepository]() + + FieldSerializer[ApiCommitListItem.Parent]() + FieldSerializer[ApiCommitListItem]() + FieldSerializer[ApiCommitListItem.Commit]() + + FieldSerializer[ApiCommitStatus]() + FieldSerializer[ApiCommit]() + FieldSerializer[ApiCombinedCommitStatus]() + + FieldSerializer[ApiPullRequest.Commit]() + def apiPathSerializer(c: Context) = new CustomSerializer[ApiPath](format => + ( + { + case JString(s) if s.startsWith(c.baseUrl) => ApiPath(s.substring(c.baseUrl.length)) + case JString(s) => throw new MappingException("Can't convert " + s + " to ApiPath") + }, + { + case ApiPath(path) => JString(c.baseUrl+path) + } + ) + ) + /** + * convert object to json string + */ + def apply(obj: AnyRef)(implicit c: Context): String = Serialization.write(obj)(jsonFormats + apiPathSerializer(c)) +} diff --git a/src/main/scala/model/AccessToken.scala b/src/main/scala/model/AccessToken.scala index acaad56..2695c2f 100644 --- a/src/main/scala/model/AccessToken.scala +++ b/src/main/scala/model/AccessToken.scala @@ -1,20 +1,20 @@ -package model - -trait AccessTokenComponent { self: Profile => - import profile.simple._ - lazy val AccessTokens = TableQuery[AccessTokens] - - class AccessTokens(tag: Tag) extends Table[AccessToken](tag, "ACCESS_TOKEN") { - val accessTokenId = column[Int]("ACCESS_TOKEN_ID", O AutoInc) - val userName = column[String]("USER_NAME") - val tokenHash = column[String]("TOKEN_HASH") - val note = column[String]("NOTE") - def * = (accessTokenId, userName, tokenHash, note) <> (AccessToken.tupled, AccessToken.unapply) - } -} -case class AccessToken( - accessTokenId: Int = 0, - userName: String, - tokenHash: String, - note: String -) +package model + +trait AccessTokenComponent { self: Profile => + import profile.simple._ + lazy val AccessTokens = TableQuery[AccessTokens] + + class AccessTokens(tag: Tag) extends Table[AccessToken](tag, "ACCESS_TOKEN") { + val accessTokenId = column[Int]("ACCESS_TOKEN_ID", O AutoInc) + val userName = column[String]("USER_NAME") + val tokenHash = column[String]("TOKEN_HASH") + val note = column[String]("NOTE") + def * = (accessTokenId, userName, tokenHash, note) <> (AccessToken.tupled, AccessToken.unapply) + } +} +case class AccessToken( + accessTokenId: Int = 0, + userName: String, + tokenHash: String, + note: String +) diff --git a/src/main/scala/model/CommitStatus.scala b/src/main/scala/model/CommitStatus.scala index 2977b26..47a2343 100644 --- a/src/main/scala/model/CommitStatus.scala +++ b/src/main/scala/model/CommitStatus.scala @@ -1,71 +1,71 @@ -package model - -import scala.slick.lifted.MappedTo -import scala.slick.jdbc._ - -trait CommitStatusComponent extends TemplateComponent { self: Profile => - import profile.simple._ - import self._ - - implicit val commitStateColumnType = MappedColumnType.base[CommitState, String](b => b.name , i => CommitState(i)) - - lazy val CommitStatuses = TableQuery[CommitStatuses] - class CommitStatuses(tag: Tag) extends Table[CommitStatus](tag, "COMMIT_STATUS") with CommitTemplate { - val commitStatusId = column[Int]("COMMIT_STATUS_ID", O AutoInc) - val context = column[String]("CONTEXT") - val state = column[CommitState]("STATE") - val targetUrl = column[Option[String]]("TARGET_URL") - val description = column[Option[String]]("DESCRIPTION") - val creator = column[String]("CREATOR") - val registeredDate = column[java.util.Date]("REGISTERED_DATE") - val updatedDate = column[java.util.Date]("UPDATED_DATE") - def * = (commitStatusId, userName, repositoryName, commitId, context, state, targetUrl, description, creator, registeredDate, updatedDate) <> (CommitStatus.tupled, CommitStatus.unapply) - def byPrimaryKey(id: Int) = commitStatusId === id.bind - } -} - -case class CommitStatus( - commitStatusId: Int = 0, - userName: String, - repositoryName: String, - commitId: String, - context: String, - state: CommitState, - targetUrl: Option[String], - description: Option[String], - creator: String, - registeredDate: java.util.Date, - updatedDate: java.util.Date -) -sealed abstract class CommitState(val name: String) -object CommitState { - object ERROR extends CommitState("error") - object FAILURE extends CommitState("failure") - object PENDING extends CommitState("pending") - object SUCCESS extends CommitState("success") - - val values: Vector[CommitState] = Vector(PENDING, SUCCESS, ERROR, FAILURE) - private val map: Map[String, CommitState] = values.map(enum => enum.name -> enum).toMap - def apply(name: String): CommitState = map(name) - def valueOf(name: String): Option[CommitState] = map.get(name) - - /** - * failure if any of the contexts report as error or failure - * pending if there are no statuses or a context is pending - * success if the latest status for all contexts is success - */ - def combine(statuses: Set[CommitState]): CommitState = { - if(statuses.isEmpty){ - PENDING - }else if(statuses.contains(CommitState.ERROR) || statuses.contains(CommitState.FAILURE)){ - FAILURE - }else if(statuses.contains(CommitState.PENDING)){ - PENDING - }else{ - SUCCESS - } - } - - implicit val getResult: GetResult[CommitState] = GetResult(r => CommitState(r.<<)) - implicit val getResultOpt: GetResult[Option[CommitState]] = GetResult(r => r.<[String].map(CommitState(_))) -} +package model + +import scala.slick.lifted.MappedTo +import scala.slick.jdbc._ + +trait CommitStatusComponent extends TemplateComponent { self: Profile => + import profile.simple._ + import self._ + + implicit val commitStateColumnType = MappedColumnType.base[CommitState, String](b => b.name , i => CommitState(i)) + + lazy val CommitStatuses = TableQuery[CommitStatuses] + class CommitStatuses(tag: Tag) extends Table[CommitStatus](tag, "COMMIT_STATUS") with CommitTemplate { + val commitStatusId = column[Int]("COMMIT_STATUS_ID", O AutoInc) + val context = column[String]("CONTEXT") + val state = column[CommitState]("STATE") + val targetUrl = column[Option[String]]("TARGET_URL") + val description = column[Option[String]]("DESCRIPTION") + val creator = column[String]("CREATOR") + val registeredDate = column[java.util.Date]("REGISTERED_DATE") + val updatedDate = column[java.util.Date]("UPDATED_DATE") + def * = (commitStatusId, userName, repositoryName, commitId, context, state, targetUrl, description, creator, registeredDate, updatedDate) <> (CommitStatus.tupled, CommitStatus.unapply) + def byPrimaryKey(id: Int) = commitStatusId === id.bind + } +} + +case class CommitStatus( + commitStatusId: Int = 0, + userName: String, + repositoryName: String, + commitId: String, + context: String, + state: CommitState, + targetUrl: Option[String], + description: Option[String], + creator: String, + registeredDate: java.util.Date, + updatedDate: java.util.Date +) +sealed abstract class CommitState(val name: String) +object CommitState { + object ERROR extends CommitState("error") + object FAILURE extends CommitState("failure") + object PENDING extends CommitState("pending") + object SUCCESS extends CommitState("success") + + val values: Vector[CommitState] = Vector(PENDING, SUCCESS, ERROR, FAILURE) + private val map: Map[String, CommitState] = values.map(enum => enum.name -> enum).toMap + def apply(name: String): CommitState = map(name) + def valueOf(name: String): Option[CommitState] = map.get(name) + + /** + * failure if any of the contexts report as error or failure + * pending if there are no statuses or a context is pending + * success if the latest status for all contexts is success + */ + def combine(statuses: Set[CommitState]): CommitState = { + if(statuses.isEmpty){ + PENDING + }else if(statuses.contains(CommitState.ERROR) || statuses.contains(CommitState.FAILURE)){ + FAILURE + }else if(statuses.contains(CommitState.PENDING)){ + PENDING + }else{ + SUCCESS + } + } + + implicit val getResult: GetResult[CommitState] = GetResult(r => CommitState(r.<<)) + implicit val getResultOpt: GetResult[Option[CommitState]] = GetResult(r => r.<[String].map(CommitState(_))) +} diff --git a/src/main/scala/service/AccesTokenService.scala b/src/main/scala/service/AccesTokenService.scala index f4ef727..4de5816 100644 --- a/src/main/scala/service/AccesTokenService.scala +++ b/src/main/scala/service/AccesTokenService.scala @@ -1,52 +1,52 @@ -package service - -import model.Profile._ -import profile.simple._ -import model.{Account, AccessToken} -import util.StringUtil -import scala.util.Random - -trait AccessTokenService { - - def makeAccessTokenString: String = { - val bytes = new Array[Byte](20) - Random.nextBytes(bytes) - bytes.map("%02x".format(_)).mkString - } - - def tokenToHash(token: String): String = StringUtil.sha1(token) - - /** - * @retuen (TokenId, Token) - */ - def generateAccessToken(userName: String, note: String)(implicit s: Session): (Int, String) = { - var token: String = null - var hash: String = null - do{ - token = makeAccessTokenString - hash = tokenToHash(token) - }while(AccessTokens.filter(_.tokenHash === hash.bind).exists.run) - val newToken = AccessToken( - userName = userName, - note = note, - tokenHash = hash) - val tokenId = (AccessTokens returning AccessTokens.map(_.accessTokenId)) += newToken - (tokenId, token) - } - - def getAccountByAccessToken(token: String)(implicit s: Session): Option[Account] = - Accounts - .innerJoin(AccessTokens) - .filter{ case (ac, t) => (ac.userName === t.userName) && (t.tokenHash === tokenToHash(token).bind) && (ac.removed === false.bind) } - .map{ case (ac, t) => ac } - .firstOption - - def getAccessTokens(userName: String)(implicit s: Session): List[AccessToken] = - AccessTokens.filter(_.userName === userName.bind).sortBy(_.accessTokenId.desc).list - - def deleteAccessToken(userName: String, accessTokenId: Int)(implicit s: Session): Unit = - AccessTokens filter (t => t.userName === userName.bind && t.accessTokenId === accessTokenId) delete - -} - -object AccessTokenService extends AccessTokenService +package service + +import model.Profile._ +import profile.simple._ +import model.{Account, AccessToken} +import util.StringUtil +import scala.util.Random + +trait AccessTokenService { + + def makeAccessTokenString: String = { + val bytes = new Array[Byte](20) + Random.nextBytes(bytes) + bytes.map("%02x".format(_)).mkString + } + + def tokenToHash(token: String): String = StringUtil.sha1(token) + + /** + * @retuen (TokenId, Token) + */ + def generateAccessToken(userName: String, note: String)(implicit s: Session): (Int, String) = { + var token: String = null + var hash: String = null + do{ + token = makeAccessTokenString + hash = tokenToHash(token) + }while(AccessTokens.filter(_.tokenHash === hash.bind).exists.run) + val newToken = AccessToken( + userName = userName, + note = note, + tokenHash = hash) + val tokenId = (AccessTokens returning AccessTokens.map(_.accessTokenId)) += newToken + (tokenId, token) + } + + def getAccountByAccessToken(token: String)(implicit s: Session): Option[Account] = + Accounts + .innerJoin(AccessTokens) + .filter{ case (ac, t) => (ac.userName === t.userName) && (t.tokenHash === tokenToHash(token).bind) && (ac.removed === false.bind) } + .map{ case (ac, t) => ac } + .firstOption + + def getAccessTokens(userName: String)(implicit s: Session): List[AccessToken] = + AccessTokens.filter(_.userName === userName.bind).sortBy(_.accessTokenId.desc).list + + def deleteAccessToken(userName: String, accessTokenId: Int)(implicit s: Session): Unit = + AccessTokens filter (t => t.userName === userName.bind && t.accessTokenId === accessTokenId) delete + +} + +object AccessTokenService extends AccessTokenService diff --git a/src/main/scala/service/CommitStatusService.scala b/src/main/scala/service/CommitStatusService.scala index fc05744..8860f77 100644 --- a/src/main/scala/service/CommitStatusService.scala +++ b/src/main/scala/service/CommitStatusService.scala @@ -1,50 +1,50 @@ -package service - -import model.Profile._ -import profile.simple._ -import model.{CommitState, CommitStatus, Account} -import util.Implicits._ -import util.StringUtil._ -import service.RepositoryService.RepositoryInfo - -trait CommitStatusService { - /** insert or update */ - def createCommitStatus(userName: String, repositoryName: String, sha:String, context:String, state:CommitState, targetUrl:Option[String], description:Option[String], now:java.util.Date, creator:Account)(implicit s: Session): Int = - CommitStatuses.filter(t => t.byCommit(userName, repositoryName, sha) && t.context===context.bind ) - .map(_.commitStatusId).firstOption match { - case Some(id:Int) => { - CommitStatuses.filter(_.byPrimaryKey(id)).map{ - t => (t.state , t.targetUrl , t.updatedDate , t.creator, t.description) - }.update( (state, targetUrl, now, creator.userName, description) ) - id - } - case None => (CommitStatuses returning CommitStatuses.map(_.commitStatusId)) += CommitStatus( - userName = userName, - repositoryName = repositoryName, - commitId = sha, - context = context, - state = state, - targetUrl = targetUrl, - description = description, - creator = creator.userName, - registeredDate = now, - updatedDate = now) - } - - def getCommitStatus(userName: String, repositoryName: String, id: Int)(implicit s: Session) :Option[CommitStatus] = - CommitStatuses.filter(t => t.byPrimaryKey(id) && t.byRepository(userName, repositoryName)).firstOption - - def getCommitStatus(userName: String, repositoryName: String, sha: String, context: String)(implicit s: Session) :Option[CommitStatus] = - CommitStatuses.filter(t => t.byCommit(userName, repositoryName, sha) && t.context===context.bind ).firstOption - - def getCommitStatues(userName: String, repositoryName: String, sha: String)(implicit s: Session) :List[CommitStatus] = - byCommitStatues(userName, repositoryName, sha).list - - def getCommitStatuesWithCreator(userName: String, repositoryName: String, sha: String)(implicit s: Session) :List[(CommitStatus, Account)] = - byCommitStatues(userName, repositoryName, sha).innerJoin(Accounts) - .filter{ case (t,a) => t.creator === a.userName }.list - - protected def byCommitStatues(userName: String, repositoryName: String, sha: String)(implicit s: Session) = - CommitStatuses.filter(t => t.byCommit(userName, repositoryName, sha) ).sortBy(_.updatedDate desc) - +package service + +import model.Profile._ +import profile.simple._ +import model.{CommitState, CommitStatus, Account} +import util.Implicits._ +import util.StringUtil._ +import service.RepositoryService.RepositoryInfo + +trait CommitStatusService { + /** insert or update */ + def createCommitStatus(userName: String, repositoryName: String, sha:String, context:String, state:CommitState, targetUrl:Option[String], description:Option[String], now:java.util.Date, creator:Account)(implicit s: Session): Int = + CommitStatuses.filter(t => t.byCommit(userName, repositoryName, sha) && t.context===context.bind ) + .map(_.commitStatusId).firstOption match { + case Some(id:Int) => { + CommitStatuses.filter(_.byPrimaryKey(id)).map{ + t => (t.state , t.targetUrl , t.updatedDate , t.creator, t.description) + }.update( (state, targetUrl, now, creator.userName, description) ) + id + } + case None => (CommitStatuses returning CommitStatuses.map(_.commitStatusId)) += CommitStatus( + userName = userName, + repositoryName = repositoryName, + commitId = sha, + context = context, + state = state, + targetUrl = targetUrl, + description = description, + creator = creator.userName, + registeredDate = now, + updatedDate = now) + } + + def getCommitStatus(userName: String, repositoryName: String, id: Int)(implicit s: Session) :Option[CommitStatus] = + CommitStatuses.filter(t => t.byPrimaryKey(id) && t.byRepository(userName, repositoryName)).firstOption + + def getCommitStatus(userName: String, repositoryName: String, sha: String, context: String)(implicit s: Session) :Option[CommitStatus] = + CommitStatuses.filter(t => t.byCommit(userName, repositoryName, sha) && t.context===context.bind ).firstOption + + def getCommitStatues(userName: String, repositoryName: String, sha: String)(implicit s: Session) :List[CommitStatus] = + byCommitStatues(userName, repositoryName, sha).list + + def getCommitStatuesWithCreator(userName: String, repositoryName: String, sha: String)(implicit s: Session) :List[(CommitStatus, Account)] = + byCommitStatues(userName, repositoryName, sha).innerJoin(Accounts) + .filter{ case (t,a) => t.creator === a.userName }.list + + protected def byCommitStatues(userName: String, repositoryName: String, sha: String)(implicit s: Session) = + CommitStatuses.filter(t => t.byCommit(userName, repositoryName, sha) ).sortBy(_.updatedDate desc) + } \ No newline at end of file diff --git a/src/main/scala/service/MergeService.scala b/src/main/scala/service/MergeService.scala index 1b7d81a..b2168ac 100644 --- a/src/main/scala/service/MergeService.scala +++ b/src/main/scala/service/MergeService.scala @@ -1,168 +1,168 @@ -package service -import util.LockUtil -import util.Directory._ -import util.Implicits._ -import util.ControlUtil._ -import org.eclipse.jgit.merge.MergeStrategy -import org.eclipse.jgit.api.Git -import org.eclipse.jgit.transport.RefSpec -import org.eclipse.jgit.errors.NoMergeBaseException -import org.eclipse.jgit.lib.{ObjectId, CommitBuilder, PersonIdent} -import model.Account -import org.eclipse.jgit.revwalk.RevWalk -trait MergeService { - import MergeService._ - /** - * Checks whether conflict will be caused in merging within pull request. - * Returns true if conflict will be caused. - */ - def checkConflict(userName: String, repositoryName: String, branch: String, issueId: Int): Boolean = { - using(Git.open(getRepositoryDir(userName, repositoryName))) { git => - MergeCacheInfo(git, branch, issueId).checkConflict() - } - } - /** - * Checks whether conflict will be caused in merging within pull request. - * only cache check. - * Returns Some(true) if conflict will be caused. - * Returns None if cache has not created yet. - */ - def checkConflictCache(userName: String, repositoryName: String, branch: String, issueId: Int): Option[Boolean] = { - using(Git.open(getRepositoryDir(userName, repositoryName))) { git => - MergeCacheInfo(git, branch, issueId).checkConflictCache() - } - } - /** merge pull request */ - def mergePullRequest(git:Git, branch: String, issueId: Int, message:String, committer:PersonIdent): Unit = { - MergeCacheInfo(git, branch, issueId).merge(message, committer) - } - /** fetch remote branch to my repository refs/pull/{issueId}/head */ - def fetchAsPullRequest(userName: String, repositoryName: String, requestUserName: String, requestRepositoryName: String, requestBranch:String, issueId:Int){ - using(Git.open(getRepositoryDir(userName, repositoryName))){ git => - git.fetch - .setRemote(getRepositoryDir(requestUserName, requestRepositoryName).toURI.toString) - .setRefSpecs(new RefSpec(s"refs/heads/${requestBranch}:refs/pull/${issueId}/head")) - .call - } - } - /** - * Checks whether conflict will be caused in merging. Returns true if conflict will be caused. - */ - def checkConflict(userName: String, repositoryName: String, branch: String, - requestUserName: String, requestRepositoryName: String, requestBranch: String): Boolean = { - using(Git.open(getRepositoryDir(requestUserName, requestRepositoryName))) { git => - val remoteRefName = s"refs/heads/${branch}" - val tmpRefName = s"refs/merge-check/${userName}/${branch}" - val refSpec = new RefSpec(s"${remoteRefName}:${tmpRefName}").setForceUpdate(true) - try { - // fetch objects from origin repository branch - git.fetch - .setRemote(getRepositoryDir(userName, repositoryName).toURI.toString) - .setRefSpecs(refSpec) - .call - // merge conflict check - val merger = MergeStrategy.RECURSIVE.newMerger(git.getRepository, true) - val mergeBaseTip = git.getRepository.resolve(s"refs/heads/${requestBranch}") - val mergeTip = git.getRepository.resolve(tmpRefName) - try { - !merger.merge(mergeBaseTip, mergeTip) - } catch { - case e: NoMergeBaseException => true - } - } finally { - val refUpdate = git.getRepository.updateRef(refSpec.getDestination) - refUpdate.setForceUpdate(true) - refUpdate.delete() - } - } - } -} -object MergeService{ - case class MergeCacheInfo(git:Git, branch:String, issueId:Int){ - val repository = git.getRepository - val mergedBranchName = s"refs/pull/${issueId}/merge" - val conflictedBranchName = s"refs/pull/${issueId}/conflict" - lazy val mergeBaseTip = repository.resolve(s"refs/heads/${branch}") - lazy val mergeTip = repository.resolve(s"refs/pull/${issueId}/head") - def checkConflictCache(): Option[Boolean] = { - Option(repository.resolve(mergedBranchName)).flatMap{ merged => - if(parseCommit( merged ).getParents().toSet == Set( mergeBaseTip, mergeTip )){ - // merged branch exists - Some(false) - }else{ - None - } - }.orElse(Option(repository.resolve(conflictedBranchName)).flatMap{ conflicted => - if(parseCommit( conflicted ).getParents().toSet == Set( mergeBaseTip, mergeTip )){ - // conflict branch exists - Some(true) - }else{ - None - } - }) - } - def checkConflict():Boolean ={ - checkConflictCache.getOrElse(checkConflictForce) - } - def checkConflictForce():Boolean ={ - val merger = MergeStrategy.RECURSIVE.newMerger(repository, true) - val conflicted = try { - !merger.merge(mergeBaseTip, mergeTip) - } catch { - case e: NoMergeBaseException => true - } - val mergeTipCommit = using(new RevWalk( repository ))(_.parseCommit( mergeTip )) - val committer = mergeTipCommit.getCommitterIdent; - def updateBranch(treeId:ObjectId, message:String, branchName:String){ - // creates merge commit - val mergeCommitId = createMergeCommit(treeId, committer, message) - // update refs - val refUpdate = repository.updateRef(branchName) - refUpdate.setNewObjectId(mergeCommitId) - refUpdate.setForceUpdate(true) - refUpdate.setRefLogIdent(committer) - refUpdate.update() - } - if(!conflicted){ - updateBranch(merger.getResultTreeId, s"Merge ${mergeTip.name} into ${mergeBaseTip.name}", mergedBranchName) - git.branchDelete().setForce(true).setBranchNames(conflictedBranchName).call() - }else{ - updateBranch(mergeTipCommit.getTree().getId(), s"can't merge ${mergeTip.name} into ${mergeBaseTip.name}", conflictedBranchName) - git.branchDelete().setForce(true).setBranchNames(mergedBranchName).call() - } - conflicted - } - // update branch from cache - def merge(message:String, committer:PersonIdent) = { - if(checkConflict()){ - throw new RuntimeException("This pull request can't merge automatically.") - } - val mergeResultCommit = parseCommit( Option(repository.resolve(mergedBranchName)).getOrElse(throw new RuntimeException(s"not found branch ${mergedBranchName}")) ) - // creates merge commit - val mergeCommitId = createMergeCommit(mergeResultCommit.getTree().getId(), committer, message) - // update refs - val refUpdate = repository.updateRef(s"refs/heads/${branch}") - refUpdate.setNewObjectId(mergeCommitId) - refUpdate.setForceUpdate(false) - refUpdate.setRefLogIdent(committer) - refUpdate.setRefLogMessage("merged", true) - refUpdate.update() - } - // return treeId - private def createMergeCommit(treeId:ObjectId, committer:PersonIdent, message:String) = { - val mergeCommit = new CommitBuilder() - mergeCommit.setTreeId(treeId) - mergeCommit.setParentIds(Array[ObjectId](mergeBaseTip, mergeTip): _*) - mergeCommit.setAuthor(committer) - mergeCommit.setCommitter(committer) - mergeCommit.setMessage(message) - // insertObject and got mergeCommit Object Id - val inserter = repository.newObjectInserter - val mergeCommitId = inserter.insert(mergeCommit) - inserter.flush() - inserter.release() - mergeCommitId - } - private def parseCommit(id:ObjectId) = using(new RevWalk( repository ))(_.parseCommit(id)) - } +package service +import util.LockUtil +import util.Directory._ +import util.Implicits._ +import util.ControlUtil._ +import org.eclipse.jgit.merge.MergeStrategy +import org.eclipse.jgit.api.Git +import org.eclipse.jgit.transport.RefSpec +import org.eclipse.jgit.errors.NoMergeBaseException +import org.eclipse.jgit.lib.{ObjectId, CommitBuilder, PersonIdent} +import model.Account +import org.eclipse.jgit.revwalk.RevWalk +trait MergeService { + import MergeService._ + /** + * Checks whether conflict will be caused in merging within pull request. + * Returns true if conflict will be caused. + */ + def checkConflict(userName: String, repositoryName: String, branch: String, issueId: Int): Boolean = { + using(Git.open(getRepositoryDir(userName, repositoryName))) { git => + MergeCacheInfo(git, branch, issueId).checkConflict() + } + } + /** + * Checks whether conflict will be caused in merging within pull request. + * only cache check. + * Returns Some(true) if conflict will be caused. + * Returns None if cache has not created yet. + */ + def checkConflictCache(userName: String, repositoryName: String, branch: String, issueId: Int): Option[Boolean] = { + using(Git.open(getRepositoryDir(userName, repositoryName))) { git => + MergeCacheInfo(git, branch, issueId).checkConflictCache() + } + } + /** merge pull request */ + def mergePullRequest(git:Git, branch: String, issueId: Int, message:String, committer:PersonIdent): Unit = { + MergeCacheInfo(git, branch, issueId).merge(message, committer) + } + /** fetch remote branch to my repository refs/pull/{issueId}/head */ + def fetchAsPullRequest(userName: String, repositoryName: String, requestUserName: String, requestRepositoryName: String, requestBranch:String, issueId:Int){ + using(Git.open(getRepositoryDir(userName, repositoryName))){ git => + git.fetch + .setRemote(getRepositoryDir(requestUserName, requestRepositoryName).toURI.toString) + .setRefSpecs(new RefSpec(s"refs/heads/${requestBranch}:refs/pull/${issueId}/head")) + .call + } + } + /** + * Checks whether conflict will be caused in merging. Returns true if conflict will be caused. + */ + def checkConflict(userName: String, repositoryName: String, branch: String, + requestUserName: String, requestRepositoryName: String, requestBranch: String): Boolean = { + using(Git.open(getRepositoryDir(requestUserName, requestRepositoryName))) { git => + val remoteRefName = s"refs/heads/${branch}" + val tmpRefName = s"refs/merge-check/${userName}/${branch}" + val refSpec = new RefSpec(s"${remoteRefName}:${tmpRefName}").setForceUpdate(true) + try { + // fetch objects from origin repository branch + git.fetch + .setRemote(getRepositoryDir(userName, repositoryName).toURI.toString) + .setRefSpecs(refSpec) + .call + // merge conflict check + val merger = MergeStrategy.RECURSIVE.newMerger(git.getRepository, true) + val mergeBaseTip = git.getRepository.resolve(s"refs/heads/${requestBranch}") + val mergeTip = git.getRepository.resolve(tmpRefName) + try { + !merger.merge(mergeBaseTip, mergeTip) + } catch { + case e: NoMergeBaseException => true + } + } finally { + val refUpdate = git.getRepository.updateRef(refSpec.getDestination) + refUpdate.setForceUpdate(true) + refUpdate.delete() + } + } + } +} +object MergeService{ + case class MergeCacheInfo(git:Git, branch:String, issueId:Int){ + val repository = git.getRepository + val mergedBranchName = s"refs/pull/${issueId}/merge" + val conflictedBranchName = s"refs/pull/${issueId}/conflict" + lazy val mergeBaseTip = repository.resolve(s"refs/heads/${branch}") + lazy val mergeTip = repository.resolve(s"refs/pull/${issueId}/head") + def checkConflictCache(): Option[Boolean] = { + Option(repository.resolve(mergedBranchName)).flatMap{ merged => + if(parseCommit( merged ).getParents().toSet == Set( mergeBaseTip, mergeTip )){ + // merged branch exists + Some(false) + }else{ + None + } + }.orElse(Option(repository.resolve(conflictedBranchName)).flatMap{ conflicted => + if(parseCommit( conflicted ).getParents().toSet == Set( mergeBaseTip, mergeTip )){ + // conflict branch exists + Some(true) + }else{ + None + } + }) + } + def checkConflict():Boolean ={ + checkConflictCache.getOrElse(checkConflictForce) + } + def checkConflictForce():Boolean ={ + val merger = MergeStrategy.RECURSIVE.newMerger(repository, true) + val conflicted = try { + !merger.merge(mergeBaseTip, mergeTip) + } catch { + case e: NoMergeBaseException => true + } + val mergeTipCommit = using(new RevWalk( repository ))(_.parseCommit( mergeTip )) + val committer = mergeTipCommit.getCommitterIdent; + def updateBranch(treeId:ObjectId, message:String, branchName:String){ + // creates merge commit + val mergeCommitId = createMergeCommit(treeId, committer, message) + // update refs + val refUpdate = repository.updateRef(branchName) + refUpdate.setNewObjectId(mergeCommitId) + refUpdate.setForceUpdate(true) + refUpdate.setRefLogIdent(committer) + refUpdate.update() + } + if(!conflicted){ + updateBranch(merger.getResultTreeId, s"Merge ${mergeTip.name} into ${mergeBaseTip.name}", mergedBranchName) + git.branchDelete().setForce(true).setBranchNames(conflictedBranchName).call() + }else{ + updateBranch(mergeTipCommit.getTree().getId(), s"can't merge ${mergeTip.name} into ${mergeBaseTip.name}", conflictedBranchName) + git.branchDelete().setForce(true).setBranchNames(mergedBranchName).call() + } + conflicted + } + // update branch from cache + def merge(message:String, committer:PersonIdent) = { + if(checkConflict()){ + throw new RuntimeException("This pull request can't merge automatically.") + } + val mergeResultCommit = parseCommit( Option(repository.resolve(mergedBranchName)).getOrElse(throw new RuntimeException(s"not found branch ${mergedBranchName}")) ) + // creates merge commit + val mergeCommitId = createMergeCommit(mergeResultCommit.getTree().getId(), committer, message) + // update refs + val refUpdate = repository.updateRef(s"refs/heads/${branch}") + refUpdate.setNewObjectId(mergeCommitId) + refUpdate.setForceUpdate(false) + refUpdate.setRefLogIdent(committer) + refUpdate.setRefLogMessage("merged", true) + refUpdate.update() + } + // return treeId + private def createMergeCommit(treeId:ObjectId, committer:PersonIdent, message:String) = { + val mergeCommit = new CommitBuilder() + mergeCommit.setTreeId(treeId) + mergeCommit.setParentIds(Array[ObjectId](mergeBaseTip, mergeTip): _*) + mergeCommit.setAuthor(committer) + mergeCommit.setCommitter(committer) + mergeCommit.setMessage(message) + // insertObject and got mergeCommit Object Id + val inserter = repository.newObjectInserter + val mergeCommitId = inserter.insert(mergeCommit) + inserter.flush() + inserter.release() + mergeCommitId + } + private def parseCommit(id:ObjectId) = using(new RevWalk( repository ))(_.parseCommit(id)) + } } \ No newline at end of file diff --git a/src/main/scala/servlet/AccessTokenAuthenticationFilter.scala b/src/main/scala/servlet/AccessTokenAuthenticationFilter.scala index 0dc3949..56e50c2 100644 --- a/src/main/scala/servlet/AccessTokenAuthenticationFilter.scala +++ b/src/main/scala/servlet/AccessTokenAuthenticationFilter.scala @@ -1,41 +1,41 @@ -package servlet - -import javax.servlet._ -import javax.servlet.http.{HttpServletRequest, HttpServletResponse} - -import service.AccessTokenService -import util.Keys -import org.scalatra.servlet.ServletApiImplicits._ -import model.Account -import org.scalatra._ - -class AccessTokenAuthenticationFilter extends Filter with AccessTokenService { - private val tokenHeaderPrefix = "token " - - override def init(filterConfig: FilterConfig): Unit = {} - - override def destroy(): Unit = {} - - override def doFilter(req: ServletRequest, res: ServletResponse, chain: FilterChain): Unit = { - implicit val request = req.asInstanceOf[HttpServletRequest] - implicit val session = req.getAttribute(Keys.Request.DBSession).asInstanceOf[slick.jdbc.JdbcBackend#Session] - val response = res.asInstanceOf[HttpServletResponse] - Option(request.getHeader("Authorization")).map{ - case auth if auth.startsWith("token ") => AccessTokenService.getAccountByAccessToken(auth.substring(6).trim).toRight(Unit) - // TODO Basic Authentication Support - case _ => Left(Unit) - }.orElse{ - Option(request.getSession.getAttribute(Keys.Session.LoginAccount).asInstanceOf[Account]).map(Right(_)) - } match { - case Some(Right(account)) => request.setAttribute(Keys.Session.LoginAccount, account); chain.doFilter(req, res) - case None => chain.doFilter(req, res) - case Some(Left(_)) => { - response.setStatus(HttpServletResponse.SC_UNAUTHORIZED) - response.setContentType("Content-Type: application/json; charset=utf-8") - val w = response.getWriter() - w.print("""{ "message": "Bad credentials" }""") - w.close() - } - } - } -} +package servlet + +import javax.servlet._ +import javax.servlet.http.{HttpServletRequest, HttpServletResponse} + +import service.AccessTokenService +import util.Keys +import org.scalatra.servlet.ServletApiImplicits._ +import model.Account +import org.scalatra._ + +class AccessTokenAuthenticationFilter extends Filter with AccessTokenService { + private val tokenHeaderPrefix = "token " + + override def init(filterConfig: FilterConfig): Unit = {} + + override def destroy(): Unit = {} + + override def doFilter(req: ServletRequest, res: ServletResponse, chain: FilterChain): Unit = { + implicit val request = req.asInstanceOf[HttpServletRequest] + implicit val session = req.getAttribute(Keys.Request.DBSession).asInstanceOf[slick.jdbc.JdbcBackend#Session] + val response = res.asInstanceOf[HttpServletResponse] + Option(request.getHeader("Authorization")).map{ + case auth if auth.startsWith("token ") => AccessTokenService.getAccountByAccessToken(auth.substring(6).trim).toRight(Unit) + // TODO Basic Authentication Support + case _ => Left(Unit) + }.orElse{ + Option(request.getSession.getAttribute(Keys.Session.LoginAccount).asInstanceOf[Account]).map(Right(_)) + } match { + case Some(Right(account)) => request.setAttribute(Keys.Session.LoginAccount, account); chain.doFilter(req, res) + case None => chain.doFilter(req, res) + case Some(Left(_)) => { + response.setStatus(HttpServletResponse.SC_UNAUTHORIZED) + response.setContentType("Content-Type: application/json; charset=utf-8") + val w = response.getWriter() + w.print("""{ "message": "Bad credentials" }""") + w.close() + } + } + } +} diff --git a/src/main/scala/util/RepoitoryName.scala b/src/main/scala/util/RepoitoryName.scala index 1642d9b..0e6edbf 100644 --- a/src/main/scala/util/RepoitoryName.scala +++ b/src/main/scala/util/RepoitoryName.scala @@ -1,18 +1,18 @@ -package util - -case class RepositoryName(owner:String, name:String){ - val fullName = s"${owner}/${name}" -} - -object RepositoryName{ - def apply(fullName: String): RepositoryName = { - fullName.split("/").toList match { - case owner :: name :: Nil => RepositoryName(owner, name) - case _ => throw new IllegalArgumentException(s"${fullName} is not repositoryName (only 'owner/name')") - } - } - def apply(repository: model.Repository): RepositoryName = RepositoryName(repository.userName, repository.repositoryName) - def apply(repository: util.JGitUtil.RepositoryInfo): RepositoryName = RepositoryName(repository.owner, repository.name) - def apply(repository: service.RepositoryService.RepositoryInfo): RepositoryName = RepositoryName(repository.owner, repository.name) - def apply(repository: model.CommitStatus): RepositoryName = RepositoryName(repository.userName, repository.repositoryName) -} +package util + +case class RepositoryName(owner:String, name:String){ + val fullName = s"${owner}/${name}" +} + +object RepositoryName{ + def apply(fullName: String): RepositoryName = { + fullName.split("/").toList match { + case owner :: name :: Nil => RepositoryName(owner, name) + case _ => throw new IllegalArgumentException(s"${fullName} is not repositoryName (only 'owner/name')") + } + } + def apply(repository: model.Repository): RepositoryName = RepositoryName(repository.userName, repository.repositoryName) + def apply(repository: util.JGitUtil.RepositoryInfo): RepositoryName = RepositoryName(repository.owner, repository.name) + def apply(repository: service.RepositoryService.RepositoryInfo): RepositoryName = RepositoryName(repository.owner, repository.name) + def apply(repository: model.CommitStatus): RepositoryName = RepositoryName(repository.userName, repository.repositoryName) +} diff --git a/src/main/twirl/account/application.scala.html b/src/main/twirl/account/application.scala.html index d2c3800..e6a5d06 100644 --- a/src/main/twirl/account/application.scala.html +++ b/src/main/twirl/account/application.scala.html @@ -1,55 +1,55 @@ -@(account: model.Account, personalTokens: List[model.AccessToken], gneratedToken:Option[(model.AccessToken, String)])(implicit context: app.Context) -@import context._ -@import view.helpers._ -@html.main("Applications"){ -