V34
Some checks failed
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline failed
ci/woodpecker/pull_request_closed/woodpecker Pipeline was successful

This commit is contained in:
mitch 2026-07-09 12:14:12 -07:00
parent e52c2875f1
commit 5adf571e0a
2 changed files with 36 additions and 31 deletions

View File

@ -73,39 +73,43 @@ steps:
drep review "${CI_REPO}" "${CI_COMMIT_PULL_REQUEST}"
echo "★ Adding ai-reviewed label to PR #${CI_COMMIT_PULL_REQUEST}"
GITEA_API="https://gitea.git.mitchecp.com/api/v1"
REPO_API="${GITEA_API}/repos/${CI_REPO_OWNER}/${CI_REPO_NAME}"
sed 's/^ //' <<'PY' | python3
import json
import os
import urllib.request
HAS_LABEL=$(curl -fsS \
-H "Authorization: token $${GITEA_TOKEN}" \
"${REPO_API}/issues/${CI_COMMIT_PULL_REQUEST}" \
| python3 -c "import json,sys; labels=json.load(sys.stdin).get('labels',[]); print('yes' if any(l.get('name')=='ai-reviewed' for l in labels) else 'no')")
token = os.environ['GITEA_TOKEN']
owner = os.environ['CI_REPO_OWNER']
repo = os.environ['CI_REPO_NAME']
pr = os.environ['CI_COMMIT_PULL_REQUEST']
label_name = 'ai-reviewed'
base = f'https://gitea.git.mitchecp.com/api/v1/repos/{owner}/{repo}'
if [ "$HAS_LABEL" = "yes" ]; then
echo "Label ai-reviewed already present on PR #${CI_COMMIT_PULL_REQUEST}"
else
LABEL_ID=$(curl -fsS \
-H "Authorization: token $${GITEA_TOKEN}" \
"${REPO_API}/labels" \
| python3 -c "import json,sys; print(next((l['id'] for l in json.load(sys.stdin) if l.get('name')=='ai-reviewed'), ''))")
def api(method, path, data=None):
headers = {'Authorization': f'token {token}'}
body = None
if data is not None:
headers['Content-Type'] = 'application/json'
body = json.dumps(data).encode()
req = urllib.request.Request(f'{base}{path}', data=body, headers=headers, method=method)
with urllib.request.urlopen(req) as resp:
return json.load(resp)
if [ -z "$LABEL_ID" ]; then
LABEL_ID=$(curl -fsS -X POST \
-H "Authorization: token $${GITEA_TOKEN}" \
-H "Content-Type: application/json" \
-d '{"name":"ai-reviewed","color":"0e8a16","description":"Drep AI review completed by Woodpecker"}' \
"${REPO_API}/labels" \
| python3 -c "import json,sys; print(json.load(sys.stdin)['id'])")
fi
curl -fsS -X POST \
-H "Authorization: token $${GITEA_TOKEN}" \
-H "Content-Type: application/json" \
-d "{\"labels\":[${LABEL_ID}]}" \
"${REPO_API}/issues/${CI_COMMIT_PULL_REQUEST}/labels"
echo "Added ai-reviewed label to PR #${CI_COMMIT_PULL_REQUEST}"
fi
issue = api('GET', f'/issues/{pr}')
if any(label.get('name') == label_name for label in issue.get('labels', [])):
print(f'Label {label_name!r} already present on PR #{pr}')
else:
labels = api('GET', '/labels')
label_id = next((label['id'] for label in labels if label.get('name') == label_name), None)
if label_id is None:
label_id = api('POST', '/labels', {
'name': label_name,
'color': '0e8a16',
'description': 'Drep AI review completed by Woodpecker',
})['id']
api('POST', f'/issues/{pr}/labels', {'labels': [label_id]})
print(f'Added label {label_name!r} to PR #{pr}')
PY
when:
event:
- pull_request
@ -119,6 +123,7 @@ steps:
from_secret: mitchecp_ssh_key
#WARN secret key(.pem) の追加は gitea ではなく woodpecker 側に必要。
#NOTE $$SSH_KEY は Woodpecker が $$ → $ に変換してから shell 実行PID 展開ではない)
commands:
- apk add --no-cache openssh-client
- mkdir -p ~/.ssh

View File

@ -1,2 +1,2 @@
<?php
echo "Hello, World! - v33";
echo "Hello, World! - v34";