Skip to content

Bump @types/node from 22.6.1 to 22.7.0 #90

Bump @types/node from 22.6.1 to 22.7.0

Bump @types/node from 22.6.1 to 22.7.0 #90

name: Merge dependabot pr
on:
pull_request
jobs:
merge-pullrequests:
runs-on: ubuntu-latest
permissions:
actions: write
checks: read
contents: write
pull-requests: write
statuses: read
pages: write
id-token: write
steps:
- uses: actions/github-script@v7
with:
script: |
const pulls = await github.request('GET /repos/{owner}/{repo}/pulls', {
owner: context.repo.owner,
repo: context.repo.repo,
})
const filtrert = pulls.data
.filter((it) => it.state == 'open')
.filter((it) => !it.head.repo.fork)
.filter((it) => it.labels.some((l) => l.name == 'automerge'))
.map((it) => {
return {
title: it.title,
number: it.number,
}
})
.map(async (it) => {
const QUERY = `query($owner: String!, $repo: String!, $pull_number: Int!) {
repository(owner: $owner, name:$repo) {
pullRequest(number:$pull_number) {
commits(last: 1) {
nodes {
commit {
statusCheckRollup {
state
}
}
}
}
}
}
}`
const result = await github.graphql(QUERY, {
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: it.number,
})
const [{ commit: lastCommit }] =
result.repository.pullRequest.commits.nodes
return {
title: it.title,
number: it.number,
checksOk: lastCommit.statusCheckRollup?.state === 'SUCCESS',
}
})
const allePrs = await Promise.all(filtrert)
const mergeablePromise = allePrs
.filter((it) => it.checksOk)
.map(async (it) => {
const prdata = await github.request('GET /repos/{owner}/{repo}/pulls/{pull_number}', {
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: it.number
})
return {
title: it.title,
number: it.number,
mergeable: prdata.data.mergeable
}
})
const mergeable = (await Promise.all(mergeablePromise))
.filter((it) => {
return it.mergeable;
})
if (mergeable.length > 0) {
const pr = mergeable[0]
console.log('Merger PR', pr.title)
await github.request('PUT /repos/{owner}/{repo}/pulls/{pull_number}/merge', {
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr.number,
merge_method: 'squash'
})
console.log('Starter main workflow')
await github.request(
'POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches',
{
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'build_and_deploy.yml',
ref: 'main',
}
)
} else {
console.log('Ingen PRer å merge')
}