Compare commits
2 Commits
7527b6185e
...
6f55f05e88
| Author | SHA1 | Date | |
|---|---|---|---|
| 6f55f05e88 | |||
| 5adf571e0a |
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user