This repository has been archived by the owner on Apr 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub-pull-requests.main.kts
executable file
·86 lines (75 loc) · 1.92 KB
/
github-pull-requests.main.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env kotlin
@file:Repository("https://jitpack.io")
@file:DependsOn("com.github.yschimke:okurl-script:2.1.0")
@file:CompilerOptions("-jvm-target", "17")
import com.baulsupp.okscript.postJsonBody
import com.baulsupp.okscript.query
import com.baulsupp.okscript.request
import com.baulsupp.okscript.runScript
import com.baulsupp.okscript.usage
data class Commit(val oid: String)
data class CommitNode(val commit: Commit)
data class Commits(val nodes: List<CommitNode>)
data class PullRequest(
val author: Author,
val title: String,
val permalink: String,
val updatedAt: String,
val commits: Commits
) {
val commit = commits.nodes.last().commit
}
data class PullRequests(val nodes: List<PullRequest>)
data class Author(
val name: String?,
val login: String
)
data class Repository(val pullRequests: PullRequests)
data class Data(val repository: Repository)
data class PullRequestResults(val data: Data) {
val pullRequests = this.data.repository.pullRequests.nodes
}
data class Query(val query: String)
if (args.size < 2) {
usage("github-pull-requests.kts org repo")
}
val (owner, repo) = args
val query = """
query {
repository(name: "$repo", owner: "$owner") {
pullRequests(first: 10, states:OPEN, orderBy:{field: UPDATED_AT, direction:DESC}) {
nodes {
author {
login
... on User {
name
}
}
title
permalink
updatedAt
commits(last:1) {
nodes {
commit {
oid
}
}
}
}
}
}
}
"""
runScript {
val results = query<PullRequestResults>(request {
url("https://api.github.com/graphql")
header("Accept", "application/vnd.github.antiope-preview")
postJsonBody(Query(query))
})
results.pullRequests.forEach {
println("Title: ${it.title}")
println("Author: ${it.author.login}")
println("Commit: ${it.commit.oid}")
println()
}
}