Skip to content

Commit c2313d2

Browse files
authored
Add workflow adding to backport project (#18772)
This adds a simple workflow that will add each PR merged to `main` to the lts-backporting project. The workflow can be skipped by using a following tag (used here intentionally): [Next only]
2 parents 835bdb4 + 59c24bf commit c2313d2

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed

Diff for: .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+

Diff for: project/scripts/addToBackportingProject.scala

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
val PROJECT_ID: String = "PVT_kwDOACj3ec4AWSoi"
12+
val FIELD_ID: String = "PVTF_lADOACj3ec4AWSoizgO7uJ4"
13+
14+
case class ID(value: String) derives WrapperVariable
15+
16+
@main def run(number: Int) =
17+
val (id, date) = getPrData(number)
18+
val newId = addItem(id)
19+
timestampItem(newId, date)
20+
21+
def getPrData(number: Int): (ID, String) =
22+
val res = query"""
23+
|query getPR {
24+
| repository(owner: "lampepfl", name:"dotty") {
25+
| pullRequest(number: $number) {
26+
| id
27+
| mergedAt
28+
| }
29+
| }
30+
|}
31+
""".send(
32+
uri"https://api.github.com/graphql",
33+
"Kordyjan",
34+
apiToken
35+
)
36+
(ID(res.repository.pullRequest.id), res.repository.pullRequest.mergedAt)
37+
38+
def timestampItem(id: ID, date: String) =
39+
query"""
40+
|mutation editField {
41+
| updateProjectV2ItemFieldValue(input: {
42+
| projectId: $PROJECT_ID,
43+
| itemId: $id,
44+
| fieldId: $FIELD_ID,
45+
| value: { text: $date }
46+
| }) {
47+
| projectV2Item {
48+
| updatedAt
49+
| }
50+
| }
51+
|}
52+
""".send(
53+
uri"https://api.github.com/graphql",
54+
"Kordyjan",
55+
apiToken
56+
)
57+
58+
def addItem(id: ID) =
59+
val res = query"""
60+
|mutation addItem {
61+
| addProjectV2ItemById(input: {
62+
| projectId: $PROJECT_ID,
63+
| contentId: $id
64+
| }) {
65+
| item {
66+
| id
67+
| }
68+
| }
69+
|}
70+
""".send(
71+
uri"https://api.github.com/graphql",
72+
"Kordyjan",
73+
apiToken
74+
)
75+
ID(res.addProjectV2ItemById.item.id)

0 commit comments

Comments
 (0)