Skip to content

Commit

Permalink
github: CheckoutPullRequest
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
  • Loading branch information
aluzzardi committed Apr 25, 2020
1 parent 0a32e1f commit 947b29b
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 50 deletions.
44 changes: 44 additions & 0 deletions pkg/github/comment_test.cue
@@ -0,0 +1,44 @@
package github

import (
"b.l/bl"
"encoding/json"
)

TestConfig: githubToken: bl.Secret

TestComment: {
query: GetPullRequest & {
token: TestConfig.githubToken
number: 2
repo: {
owner: "stackbrew-test"
name: "gh-test"
}
}

addComment: AddComment & {
token: TestConfig.githubToken
subjectId: query.pullRequest.id
body: #"""
## Stackbrew Test
```
\#(json.Indent(
json.Marshal(query.pullRequest),
"", " "
))
```
"""#
}

updateComment: UpdateComment & {
token: TestConfig.githubToken
commentId: addComment.comment.id
body: #"""
\#(addComment.body)
**UPDATED**
"""#
}
}
20 changes: 20 additions & 0 deletions pkg/github/pull_request.cue
@@ -1,5 +1,10 @@
package github

import (
"b.l/bl"
"stackbrew.io/git"
)

PullRequest :: {
id: string
state: string
Expand Down Expand Up @@ -69,6 +74,21 @@ GetPullRequest :: {
pullRequest: data.repository.pullRequest
}

// FIXME: this should be PullRequest::Checkout
CheckoutPullRequest :: {
pullRequest: PullRequest

// Github API token
token: bl.Secret

git.Repository & {
url: pullRequest.headRepository.url
ref: pullRequest.headRef.target.oid
username: "apikey"
httpPassword: token
}
}

ListPullRequests :: {
repo: {
owner: string
Expand Down
24 changes: 24 additions & 0 deletions pkg/github/pull_request_test.cue
Expand Up @@ -50,6 +50,30 @@ TestGetPullRequestOpen: {
}
}

TestCheckoutPullRequest: {
query: GetPullRequest & {
token: TestConfig.githubToken
number: 2
repo: {
owner: "stackbrew-test"
name: "gh-test"
}
}

checkout: CheckoutPullRequest & {
token: TestConfig.githubToken
pullRequest: query.pullRequest
}

test: bl.BashScript & {
runPolicy: "always"
input: "/checkout": checkout.out
code: """
grep -q "FROM PR2" /checkout/README.md
"""
}
}

TestListPullRequests: {
query: ListPullRequests & {
token: TestConfig.githubToken
Expand Down
25 changes: 5 additions & 20 deletions pkg/github/repository.cue
Expand Up @@ -2,7 +2,6 @@ package github

import (
"b.l/bl"
"stackbrew.io/git"
)

Repository :: {
Expand All @@ -15,25 +14,11 @@ Repository :: {
// Github API token
token: bl.Secret

PullRequest :: {
number: int

checkout: gitCloneAndCheckout.out

info: GetPullRequest & {
"number": number
"token": token
repo: {
"owner": owner
"name": name
}
}

gitCloneAndCheckout: git.Repository & {
url: info.pullRequest.headRepository.url
ref: info.pullRequest.headRef.target.oid
username: "apikey"
httpPassword: token
"GetPullRequest" :: GetPullRequest & {
"token": token
repo: {
"owner": owner
"name": name
}
}
}
38 changes: 8 additions & 30 deletions pkg/github/repository_test.cue
Expand Up @@ -2,53 +2,31 @@ package github

import (
"b.l/bl"
"encoding/json"
)

TestConfig: githubToken: bl.Secret

TestPullRequest: {
TestRepository: {
repository: Repository & {
name: "gh-test"
owner: "stackbrew-test"
token: TestConfig.githubToken
}


pr: repository.PullRequest & {
pr: repository.GetPullRequest & {
number: 2
}

checkout: CheckoutPullRequest & {
pullRequest: pr.pullRequest
token: TestConfig.githubToken
}

test: bl.BashScript & {
runPolicy: "always"
input: "/checkout": pr.checkout
input: "/checkout": checkout.out
code: """
grep -q "FROM PR2" /checkout/README.md
"""
}

comment: AddComment & {
token: TestConfig.githubToken
subjectId: pr.info.pullRequest.id
body: #"""
## Stackbrew Test
```
\#(json.Indent(
json.Marshal(pr.info),
"", " "
))
```
"""#
}

updateComment: UpdateComment & {
token: TestConfig.githubToken
commentId: comment.comment.id
body: #"""
\#(comment.body)
**UPDATED**
"""#
}
}

0 comments on commit 947b29b

Please sign in to comment.