Skip to content

Commit a32817e

Browse files
committed
Add workflow adding to backport project
1 parent f62429b commit a32817e

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed

.github/workflows/lts-backport.yaml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Add to backporting project
2+
3+
on:
4+
pull_request:
5+
types:
6+
- closed
7+
8+
jobs:
9+
add-to-backporting-project:
10+
if: "github.event.pull_request.merged == true
11+
&& github.event.pull_request.base.ref == 'main'
12+
&& !contains(github.event.pull_request.body, '[Next only]')"
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v3
17+
with:
18+
fetch-depth: 0
19+
- uses: coursier/cache-action@v6
20+
- uses: VirtusLab/[email protected]
21+
- run: scala-cli ./project/scripts/addToBackportingProject.scala -- ${{ github.event.pull_request.number }}
22+
env:
23+
GRAPHQL_API_TOKEN: ${{ secrets.GRAPHQL_API_TOKEN }}
24+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
//> using scala 3.3.1
2+
//> using toolkit 0.2.1
3+
//> using lib pro.kordyjan::pytanie:0.1.6
4+
5+
import pytanie.*
6+
import sttp.client4.*
7+
8+
lazy val apiToken =
9+
System.getenv("GRAPHQL_API_TOKEN")
10+
11+
case class ID(value: String) derives WrapperVariable
12+
13+
@main def run(number: Int) =
14+
val (id, date) = getPrData(number)
15+
val newId = addItem(id)
16+
timestampItem(newId, date)
17+
18+
def getPrData(number: Int): (ID, String) =
19+
val res = query"""
20+
|query getPR {
21+
| repository(owner: "lampepfl", name:"dotty") {
22+
| pullRequest(number: 17570) {
23+
| id
24+
| mergedAt
25+
| }
26+
| }
27+
|}
28+
""".send(
29+
uri"https://api.github.com/graphql",
30+
"Kordyjan",
31+
apiToken
32+
)
33+
(ID(res.repository.pullRequest.id), res.repository.pullRequest.mergedAt)
34+
35+
def timestampItem(id: ID, date: String) =
36+
query"""
37+
|mutation editField {
38+
| updateProjectV2ItemFieldValue(input: {
39+
| projectId: "PVT_kwDOACj3ec4AWSoi",
40+
| itemId: $id,
41+
| fieldId: "PVTF_lADOACj3ec4AWSoizgO7uJ4",
42+
| value: { text: $date }
43+
| }) {
44+
| projectV2Item {
45+
| updatedAt
46+
| }
47+
| }
48+
|}
49+
""".send(
50+
uri"https://api.github.com/graphql",
51+
"Kordyjan",
52+
apiToken
53+
)
54+
55+
def addItem(id: ID) =
56+
val res = query"""
57+
|mutation addItem {
58+
| addProjectV2ItemById(input: {
59+
| projectId: "PVT_kwDOACj3ec4AWSoi",
60+
| contentId: $id
61+
| }) {
62+
| item {
63+
| id
64+
| }
65+
| }
66+
|}
67+
""".send(
68+
uri"https://api.github.com/graphql",
69+
"Kordyjan",
70+
apiToken
71+
)
72+
ID(res.addProjectV2ItemById.item.id)

0 commit comments

Comments
 (0)