diff --git a/.github/workflows/lts-backport.yaml b/.github/workflows/lts-backport.yaml new file mode 100644 index 000000000000..98dc6c648e21 --- /dev/null +++ b/.github/workflows/lts-backport.yaml @@ -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/scala-cli-setup@v0.2 + - run: scala-cli ./project/scripts/addToBackportingProject.scala -- ${{ github.event.pull_request.number }} + env: + GRAPHQL_API_TOKEN: ${{ secrets.GRAPHQL_API_TOKEN }} + diff --git a/project/scripts/addToBackportingProject.scala b/project/scripts/addToBackportingProject.scala new file mode 100644 index 000000000000..eeb61ab5a7b7 --- /dev/null +++ b/project/scripts/addToBackportingProject.scala @@ -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) \ No newline at end of file