Skip to content

Commit

Permalink
Use graphql in a more elegant way
Browse files Browse the repository at this point in the history
  • Loading branch information
hustcer committed Oct 24, 2024
1 parent 9ed1250 commit 3c31703
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
6 changes: 3 additions & 3 deletions nu/issue.gql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
repository(owner: "__repo_owner__", name: "__repo_name__") {
issueOrPullRequest(number: __issue_number__) {
query issueCloser($repo_owner: String!, $repo_name: String!, $issue_number: Int!) {
repository(owner: $repo_owner, name: $repo_name) {
issueOrPullRequest(number: $issue_number) {
__typename
... on Closable {
closed
Expand Down
16 changes: 9 additions & 7 deletions nu/query.nu
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@
# query-issue-closer-by-graphql web-infra-dev/rsbuild 3780 <token>

export def query-issue-closer-by-graphql [
repo: string, # Github repository name
issueNO: string, # Issue number
token: string # Github access token
repo: string, # Github repository name
issueNO: int, # Issue number
token: string # Github access token
] {
let owner = $repo | split row / | first
let name = $repo | split row / | last
let query = open -r nu/issue.gql
| str replace __repo_name__ $name
| str replace __repo_owner__ $owner
| str replace __issue_number__ $issueNO
let variables = {
repo_name: $name,
repo_owner: $owner,
issue_number: $issueNO
}

let payload = { query: $query } | to json
const QUERY_API = 'https://api.github.com/graphql'
let HEADERS = ['Authorization' $'bearer ($token)']
let rename = {
Expand All @@ -29,6 +30,7 @@ export def query-issue-closer-by-graphql [
'mergeCommit.abbreviatedOid': 'sha'
}

let payload = { query: $query, variables: $variables } | to json
let result = http post --content-type application/json -H $HEADERS $QUERY_API $payload
| get data.repository.issueOrPullRequest

Expand Down

0 comments on commit 3c31703

Please sign in to comment.