Skip to content

Commit

Permalink
Add workflow adding to backport project (#18772)
Browse files Browse the repository at this point in the history
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]
  • Loading branch information
Kordyjan authored Oct 27, 2023
2 parents 835bdb4 + 59c24bf commit c2313d2
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/lts-backport.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Add to backporting project

on:
pull_request:
types:
- closed

jobs:
add-to-backporting-project:
if: "github.event.pull_request.merged == true
&& github.event.pull_request.base.ref == 'main'
&& !contains(github.event.pull_request.body, '[Next only]')"
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: coursier/cache-action@v6
- uses: VirtusLab/[email protected]
- run: scala-cli ./project/scripts/addToBackportingProject.scala -- ${{ github.event.pull_request.number }}
env:
GRAPHQL_API_TOKEN: ${{ secrets.GRAPHQL_API_TOKEN }}

75 changes: 75 additions & 0 deletions project/scripts/addToBackportingProject.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//> using scala 3.3.1
//> using toolkit 0.2.1
//> using lib pro.kordyjan::pytanie:0.1.6

import pytanie.*
import sttp.client4.*

lazy val apiToken =
System.getenv("GRAPHQL_API_TOKEN")

val PROJECT_ID: String = "PVT_kwDOACj3ec4AWSoi"
val FIELD_ID: String = "PVTF_lADOACj3ec4AWSoizgO7uJ4"

case class ID(value: String) derives WrapperVariable

@main def run(number: Int) =
val (id, date) = getPrData(number)
val newId = addItem(id)
timestampItem(newId, date)

def getPrData(number: Int): (ID, String) =
val res = query"""
|query getPR {
| repository(owner: "lampepfl", name:"dotty") {
| pullRequest(number: $number) {
| id
| mergedAt
| }
| }
|}
""".send(
uri"https://api.github.com/graphql",
"Kordyjan",
apiToken
)
(ID(res.repository.pullRequest.id), res.repository.pullRequest.mergedAt)

def timestampItem(id: ID, date: String) =
query"""
|mutation editField {
| updateProjectV2ItemFieldValue(input: {
| projectId: $PROJECT_ID,
| itemId: $id,
| fieldId: $FIELD_ID,
| value: { text: $date }
| }) {
| projectV2Item {
| updatedAt
| }
| }
|}
""".send(
uri"https://api.github.com/graphql",
"Kordyjan",
apiToken
)

def addItem(id: ID) =
val res = query"""
|mutation addItem {
| addProjectV2ItemById(input: {
| projectId: $PROJECT_ID,
| contentId: $id
| }) {
| item {
| id
| }
| }
|}
""".send(
uri"https://api.github.com/graphql",
"Kordyjan",
apiToken
)
ID(res.addProjectV2ItemById.item.id)

0 comments on commit c2313d2

Please sign in to comment.