Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
github: imported package from acme demo
Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
- Loading branch information
Showing
12 changed files
with
494 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package github | ||
|
||
import ( | ||
"b.l/bl" | ||
) | ||
|
||
Comment :: { | ||
id: string | ||
body: string | ||
} | ||
|
||
CommentFragment :: """ | ||
fragment CommentParts on IssueComment { | ||
id | ||
body | ||
} | ||
""" | ||
|
||
AddComment :: { | ||
subjectId: string | ||
body: string | ||
token: bl.Secret | ||
|
||
comment: Comment & { | ||
id: do.data.addComment.commentEdge.node.id | ||
body: do.data.addComment.commentEdge.node.body | ||
} | ||
|
||
do: Query & { | ||
query: """ | ||
mutation ($input: AddCommentInput!) { | ||
addComment(input: $input) { | ||
subject { | ||
id | ||
} | ||
commentEdge { | ||
node { | ||
...CommentParts | ||
} | ||
} | ||
} | ||
} | ||
\(CommentFragment) | ||
""" | ||
|
||
variable: input: { | ||
"subjectId": subjectId | ||
"body": body | ||
} | ||
|
||
"token": token | ||
} | ||
} | ||
|
||
UpdateComment :: { | ||
commentId: string | ||
body: string | ||
token: bl.Secret | ||
|
||
comment: Comment & { | ||
id: do.data.updateIssueComment.issueComment.id | ||
body: do.data.updateIssueComment.issueComment.body | ||
} | ||
|
||
do: Query & { | ||
query: """ | ||
mutation ($input: UpdateIssueCommentInput!) { | ||
updateIssueComment(input: $input) { | ||
issueComment { | ||
...CommentParts | ||
} | ||
} | ||
} | ||
\(CommentFragment) | ||
""" | ||
|
||
variable: input: { | ||
id: commentId | ||
"body": body | ||
} | ||
|
||
"token": token | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package github | ||
|
||
import ( | ||
"b.l/bl" | ||
) | ||
|
||
PullRequest :: { | ||
id: string | ||
state: string | ||
number: int | ||
title: string | ||
headRepository: { | ||
sshUrl: string | ||
url: string | ||
} | ||
headRef: { | ||
name: string | ||
prefix: string | ||
target: oid: string | ||
} | ||
} | ||
|
||
// INTERNAL: GraphQL fragment shared across queries related to PullRequest | ||
PullRequestParts :: """ | ||
fragment PullRequestParts on PullRequest { | ||
id | ||
state | ||
number | ||
title | ||
headRepository { | ||
sshUrl | ||
url | ||
} | ||
headRef { | ||
name | ||
prefix | ||
target { | ||
oid | ||
} | ||
} | ||
} | ||
""" | ||
|
||
GetPullRequest :: { | ||
number: int | ||
|
||
repo: { | ||
owner: string | ||
name: string | ||
} | ||
|
||
Query & { | ||
query: | ||
""" | ||
query($owner: String!, $name: String!, $number: Int!) { | ||
repository(owner: $owner, name: $name) { | ||
pullRequest(number: $number) { | ||
...PullRequestParts | ||
} | ||
} | ||
} | ||
\(PullRequestParts) | ||
""" | ||
variable: { | ||
owner: repo.owner | ||
name: repo.name | ||
"number": number | ||
} | ||
} | ||
|
||
data: _ | ||
pullRequest: PullRequest | ||
pullRequest: data.repository.pullRequest | ||
} | ||
|
||
ListPullRequests :: { | ||
repo: { | ||
owner: string | ||
name: string | ||
} | ||
pageSize: int | *25 | ||
token: bl.Secret | ||
states: [string] | *[] | ||
|
||
Query & { | ||
query: | ||
""" | ||
query($owner: String!, $name: String!, $last: Int, $states: [PullRequestState!]) { | ||
repository(owner: $owner, name: $name) { | ||
pullRequests(last: $last, states: $states) { | ||
nodes { | ||
...PullRequestParts | ||
} | ||
} | ||
} | ||
} | ||
\(PullRequestParts) | ||
""" | ||
variable: { | ||
owner: repo.owner | ||
name: repo.name | ||
last: pageSize | ||
"states": states | ||
} | ||
} | ||
|
||
data: _ | ||
pullRequests: [...PullRequest] | ||
pullRequests: data.repository.pullRequests.nodes | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package github | ||
|
||
import ( | ||
"b.l/bl" | ||
) | ||
|
||
TestConfig: githubToken: bl.Secret | ||
|
||
TestGetPullRequestMerged: { | ||
query: GetPullRequest & { | ||
token: TestConfig.githubToken | ||
number: 1 | ||
repo: { | ||
owner: "stackbrew-test" | ||
name: "gh-test" | ||
} | ||
} | ||
|
||
test: bl.BashScript & { | ||
runPolicy: "always" | ||
environment: state: query.pullRequest.state | ||
code: """ | ||
test "$state" = "MERGED" | ||
""" | ||
} | ||
} | ||
|
||
TestGetPullRequestOpen: { | ||
query: GetPullRequest & { | ||
token: TestConfig.githubToken | ||
number: 2 | ||
repo: { | ||
owner: "stackbrew-test" | ||
name: "gh-test" | ||
} | ||
} | ||
|
||
test: bl.BashScript & { | ||
runPolicy: "always" | ||
environment: { | ||
state: query.pullRequest.state | ||
gitUrl: query.pullRequest.headRepository.url | ||
commit: query.pullRequest.headRef.target.oid | ||
} | ||
code: """ | ||
test "$state" = "OPEN" | ||
test "$gitUrl" = "https://github.com/stackbrew-test/gh-test" | ||
test "$commit" = "16a9a0fffda42bfbab40cfba79ecef61c7343e65" | ||
""" | ||
} | ||
} | ||
|
||
TestListPullRequests: { | ||
query: ListPullRequests & { | ||
token: TestConfig.githubToken | ||
pageSize: 10 | ||
states: ["MERGED"] | ||
repo: { | ||
owner: "stackbrew-test" | ||
name: "gh-test" | ||
} | ||
} | ||
|
||
test: bl.BashScript & { | ||
runPolicy: "always" | ||
environment: { | ||
FIRST_PR_STATE: "\(query.pullRequests[0].state)" | ||
for pr in query.pullRequests { | ||
"PR_\(pr.number)_STATE": pr.state | ||
} | ||
} | ||
code: """ | ||
env | ||
test "$FIRST_PR_STATE" = "MERGED" | ||
test "$PR_1_STATE" = "MERGED" | ||
test -z "$PR_2_STATE" | ||
""" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package github | ||
|
||
// A client for the Github API v4, also known as the "Github GraphQL API" | ||
// Reference: https://developer.github.com/v4/ | ||
|
||
import ( | ||
"stackbrew.io/graphql" | ||
) | ||
|
||
// GitHub v4 GraphQL Query | ||
Query :: graphql.Query & { | ||
url: "https://api.github.com/graphql" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package github | ||
|
||
import ( | ||
"b.l/bl" | ||
"stackbrew.io/git" | ||
) | ||
|
||
Repository :: { | ||
// Github repository name | ||
name: string | ||
|
||
// Github repository owner | ||
owner: string | ||
|
||
// 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 | ||
} | ||
} | ||
} |
Oops, something went wrong.