Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add workflow adding to backport project #18772

Merged
merged 2 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading