|
| 1 | +name: Generate Weekly Community Report 📊 |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '0 12 * * 1' # Run at 12:00 UTC on Monday |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + days: |
| 9 | + description: 'Number of days to look back for the report' |
| 10 | + required: true |
| 11 | + default: '7' |
| 12 | + |
| 13 | +jobs: |
| 14 | + generate-report: |
| 15 | + name: Generate Report 📝 |
| 16 | + runs-on: ubuntu-latest |
| 17 | + permissions: |
| 18 | + issues: write |
| 19 | + pull-requests: read |
| 20 | + discussions: read |
| 21 | + contents: read |
| 22 | + id-token: write |
| 23 | + |
| 24 | + steps: |
| 25 | + - name: Generate GitHub App Token 🔑 |
| 26 | + id: generate_token |
| 27 | + uses: actions/create-github-app-token@v1 |
| 28 | + with: |
| 29 | + app-id: ${{ secrets.APP_ID }} |
| 30 | + private-key: ${{ secrets.PRIVATE_KEY }} |
| 31 | + |
| 32 | + - name: Generate Report 📜 |
| 33 | + id: report |
| 34 | + env: |
| 35 | + GH_TOKEN: ${{ steps.generate_token.outputs.token }} |
| 36 | + REPO: ${{ github.repository }} |
| 37 | + DAYS: ${{ github.event.inputs.days || '7' }} |
| 38 | + run: | |
| 39 | + set -e |
| 40 | +
|
| 41 | + START_DATE=$(date -u -d "$DAYS days ago" +'%Y-%m-%d') |
| 42 | + END_DATE=$(date -u +'%Y-%m-%d') |
| 43 | + echo "⏳ Generating report for contributions from $START_DATE to $END_DATE..." |
| 44 | +
|
| 45 | + declare -A author_is_googler |
| 46 | + check_googler_status() { |
| 47 | + local author=$1 |
| 48 | + if [[ "$author" == *"[bot]" ]]; then |
| 49 | + author_is_googler[$author]=1 |
| 50 | + return 1 |
| 51 | + fi |
| 52 | + if [[ -v "author_is_googler[$author]" ]]; then |
| 53 | + return ${author_is_googler[$author]} |
| 54 | + fi |
| 55 | +
|
| 56 | + if gh api "orgs/googlers/members/$author" --silent 2>/dev/null; then |
| 57 | + echo "🧑💻 $author is a Googler." |
| 58 | + author_is_googler[$author]=0 |
| 59 | + else |
| 60 | + echo "🌍 $author is a community contributor." |
| 61 | + author_is_googler[$author]=1 |
| 62 | + fi |
| 63 | + return ${author_is_googler[$author]} |
| 64 | + } |
| 65 | +
|
| 66 | + googler_issues=0 |
| 67 | + non_googler_issues=0 |
| 68 | + googler_prs=0 |
| 69 | + non_googler_prs=0 |
| 70 | +
|
| 71 | + echo "🔎 Fetching issues and pull requests..." |
| 72 | + ITEMS_JSON=$(gh search issues --repo "$REPO" "created:>$START_DATE" --json author,isPullRequest --limit 1000) |
| 73 | +
|
| 74 | + for row in $(echo "${ITEMS_JSON}" | jq -r '.[] | @base64'); do |
| 75 | + _jq() { |
| 76 | + echo ${row} | base64 --decode | jq -r ${1} |
| 77 | + } |
| 78 | + author=$(_jq '.author.login') |
| 79 | + is_pr=$(_jq '.isPullRequest') |
| 80 | +
|
| 81 | + if [[ -z "$author" || "$author" == "null" ]]; then |
| 82 | + continue |
| 83 | + fi |
| 84 | +
|
| 85 | + if check_googler_status "$author"; then |
| 86 | + if [[ "$is_pr" == "true" ]]; then |
| 87 | + ((googler_prs++)) |
| 88 | + else |
| 89 | + ((googler_issues++)) |
| 90 | + fi |
| 91 | + else |
| 92 | + if [[ "$is_pr" == "true" ]]; then |
| 93 | + ((non_googler_prs++)) |
| 94 | + else |
| 95 | + ((non_googler_issues++)) |
| 96 | + fi |
| 97 | + fi |
| 98 | + done |
| 99 | +
|
| 100 | + googler_discussions=0 |
| 101 | + non_googler_discussions=0 |
| 102 | +
|
| 103 | + echo "🗣️ Fetching discussions..." |
| 104 | + DISCUSSION_QUERY=''' |
| 105 | + query($q: String!) { |
| 106 | + search(query: $q, type: DISCUSSION, first: 100) { |
| 107 | + nodes { |
| 108 | + ... on Discussion { |
| 109 | + author { |
| 110 | + login |
| 111 | + } |
| 112 | + } |
| 113 | + } |
| 114 | + } |
| 115 | + }''' |
| 116 | + DISCUSSIONS_JSON=$(gh api graphql -f q="repo:$REPO created:>$START_DATE" -f query="$DISCUSSION_QUERY") |
| 117 | +
|
| 118 | + for row in $(echo "${DISCUSSIONS_JSON}" | jq -r '.data.search.nodes[] | @base64'); do |
| 119 | + _jq() { |
| 120 | + echo ${row} | base64 --decode | jq -r ${1} |
| 121 | + } |
| 122 | + author=$(_jq '.author.login') |
| 123 | +
|
| 124 | + if [[ -z "$author" || "$author" == "null" ]]; then |
| 125 | + continue |
| 126 | + fi |
| 127 | +
|
| 128 | + if check_googler_status "$author"; then |
| 129 | + ((googler_discussions++)) |
| 130 | + else |
| 131 | + ((non_googler_discussions++)) |
| 132 | + fi |
| 133 | + done |
| 134 | +
|
| 135 | + echo "✍️ Generating report content..." |
| 136 | + REPORT_TITLE="Community Contribution Report: $START_DATE to $END_DATE" |
| 137 | + TOTAL_ISSUES=$((googler_issues + non_googler_issues)) |
| 138 | + TOTAL_PRS=$((googler_prs + non_googler_prs)) |
| 139 | + TOTAL_DISCUSSIONS=$((googler_discussions + non_googler_discussions)) |
| 140 | +
|
| 141 | + REPORT_BODY=$(cat <<EOF |
| 142 | + ### 💖 Community Contribution Report |
| 143 | +
|
| 144 | + **Period:** $START_DATE to $END_DATE |
| 145 | +
|
| 146 | + | Category | Googlers | Community | Total | |
| 147 | + |---|---:|---:|---:| |
| 148 | + | **Issues** | $googler_issues | $non_googler_issues | **$TOTAL_ISSUES** | |
| 149 | + | **Pull Requests** | $googler_prs | $non_googler_prs | **$TOTAL_PRS** | |
| 150 | + | **Discussions** | $googler_discussions | $non_googler_discussions | **$TOTAL_DISCUSSIONS** | |
| 151 | +
|
| 152 | + _This report was generated automatically by a GitHub Action._ |
| 153 | + EOF |
| 154 | + ) |
| 155 | +
|
| 156 | + echo "report_body<<EOF" >> $GITHUB_OUTPUT |
| 157 | + echo "$REPORT_BODY" >> $GITHUB_OUTPUT |
| 158 | + echo "EOF" >> $GITHUB_OUTPUT |
| 159 | +
|
| 160 | + echo "📊 Community Contribution Report:" |
| 161 | + echo "$REPORT_BODY" |
| 162 | +
|
| 163 | + - name: 🤖 Get Insights from Report |
| 164 | + if: steps.report.outputs.report_body != '' |
| 165 | + uses: google-gemini/gemini-cli-action@41c0f1b3cbd1a0b284251bd1aac034edd07a3a2f |
| 166 | + env: |
| 167 | + GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }} |
| 168 | + with: |
| 169 | + version: 0.1.8-rc.0 |
| 170 | + GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }} |
| 171 | + OTLP_GCP_WIF_PROVIDER: ${{ secrets.OTLP_GCP_WIF_PROVIDER }} |
| 172 | + OTLP_GCP_SERVICE_ACCOUNT: ${{ secrets.OTLP_GCP_SERVICE_ACCOUNT }} |
| 173 | + OTLP_GOOGLE_CLOUD_PROJECT: ${{ secrets.OTLP_GOOGLE_CLOUD_PROJECT }} |
| 174 | + settings_json: | |
| 175 | + { |
| 176 | + "coreTools": [ |
| 177 | + "run_shell_command(gh issue list)", |
| 178 | + "run_shell_command(gh pr list)", |
| 179 | + "run_shell_command(gh search issues)", |
| 180 | + "run_shell_command(gh search prs)" |
| 181 | + ] |
| 182 | + } |
| 183 | + prompt: | |
| 184 | + You are a helpful assistant that analyzes community contribution reports. |
| 185 | + Based on the following report, please provide a brief summary and highlight any interesting trends or potential areas for improvement. |
| 186 | +
|
| 187 | + Report: |
| 188 | + ${{ steps.report.outputs.report_body }} |
0 commit comments