Skip to content

PR merge on time v3.2 by crong #17

PR merge on time v3.2 by crong

PR merge on time v3.2 by crong #17

Workflow file for this run

name: "PR merge on time v3.2 by crong"
on:
schedule:
- cron: "0 13 * * 3,5"
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
permissions:
contents: write
pull-requests: write
issues: write
jobs:
merge:
name: "Auto Merge on time"
runs-on: "ubuntu-latest"
steps:
- name: "Merge pull request"
uses: "actions/github-script@v6"
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const query = `query($owner:String!, $name:String!) {
repository(owner: $owner, name: $name) {
pullRequests(last: 100, states: OPEN) {
edges {
node {
number
headRefName
baseRefName
author {
login
}
repository {
name
}
mergeable
labels(first: 10) {
nodes {
name
}
}
reviews(last: 1) {
nodes {
state
}
}
}
}
}
}
}`
const variables = {
owner: context.repo.owner,
name: context.repo.repo,
}
const {repository:{pullRequests:{edges: list}}} = await github.graphql(query, variables)
for( let {node} of list) {
if(node.baseRefName === "main" || !node.labels.nodes.length) {
//add comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: node.number,
body: "main 브랜치로 병합 시도 || 적절한 라벨이 있는지 확인해 주세요."
})
continue;
}
if (node.reviews.nodes.length && node.reviews.nodes[0].state === "CHANGES_REQUESTED") {
//add comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: node.number,
body: "변경 요청 중인 브랜치의 머지를 연기합니다."
})
continue;
}
try {
if(node.mergeable === "CONFLICTING") {
// add comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: node.number,
body: "충돌로 인해 자동 병합이 불가능합니다."
})
// close pull request
await github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: node.number,
state: "closed"
})
} else {
//add comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: node.number,
body: "자동 병합 완료"
})
// merge pull request
await github.rest.pulls.merge({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: node.number,
merge_method: "merge"
})
}
} catch (e) {
console.log("error", e);
}
}