Something went wrong. Try again.
POC for a database of flagged users on github
Something went wrong. Try again.
2.0 kB · 60 lines
Shell
at main
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061#!/usr/bin/env bashset -euo pipefail
# Process a trusted reporter application# Expected environment variables (from issue parser):# REPOSITORY - owner/repo applying to join# MAINTAINER - GitHub username claiming maintainership# ISSUE_AUTHOR - the GitHub username that opened the issue
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"DATA_DIR="$REPO_ROOT/data"TRUSTED_REPOS="$DATA_DIR/trusted-repos.json"
# Validate required fieldsif [[ -z "${REPOSITORY:-}" ]]; then echo "::error::Missing required field: repository" exit 1fi
if [[ -z "${MAINTAINER:-}" ]]; then echo "::error::Missing required field: maintainer" exit 1fi
if [[ -z "${ISSUE_AUTHOR:-}" ]]; then echo "::error::Missing required field: issue_author" exit 1fi
# Verify issue author matches claimed maintainerif [[ "${ISSUE_AUTHOR,,}" != "${MAINTAINER,,}" ]]; then echo "::error::Issue author ($ISSUE_AUTHOR) does not match claimed maintainer ($MAINTAINER)" echo "result=author_mismatch" >> "$GITHUB_OUTPUT" exit 1fi
# Check if already trustedif jq -e --arg repo "$REPOSITORY" 'map(ascii_downcase) | index($repo | ascii_downcase)' "$TRUSTED_REPOS" > /dev/null 2>&1; then echo "::error::Repository '$REPOSITORY' is already in the trusted reporter network" echo "result=already_trusted" >> "$GITHUB_OUTPUT" exit 1fi
# Verify the repository exists on GitHubHTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" "https://api.github.com/repos/${REPOSITORY}" \ -H "Accept: application/vnd.github.v3+json" \ ${GITHUB_TOKEN:+-H "Authorization: token $GITHUB_TOKEN"})
if [[ "$HTTP_STATUS" != "200" ]]; then echo "::error::Repository '$REPOSITORY' does not exist or is not accessible (HTTP $HTTP_STATUS)" echo "result=repo_not_found" >> "$GITHUB_OUTPUT" exit 1fi
# Add to trusted reposjq --arg repo "$REPOSITORY" '. += [$repo]' "$TRUSTED_REPOS" > "${TRUSTED_REPOS}.tmp" \ && mv "${TRUSTED_REPOS}.tmp" "$TRUSTED_REPOS"
echo "Added $REPOSITORY to trusted reporter network"echo "result=success" >> "$GITHUB_OUTPUT"