Skip to content

Commit 9de57d0

Browse files
locus313Copilot
andauthored
fix: standardize CSV/report output locations across scripts (#56)
Several reporting scripts wrote their output inconsistently: some to a 'reports/' subdirectory (with differing CWD- vs script-dir-relative defaults), others to a hardcoded filename in the current directory. - github-copilot-report.sh and github-repo-permissions-report.sh now default their CSV output into $REPORT_DIR (default ./reports, overridable via env var or their existing -o/--output flag). - github-close-archived-repo-security-alerts.sh: renamed the script-local REPORTS_DIR variable to the standard REPORT_DIR, exposed it as an env var/action input, and defaulted it to ./reports to match every other reporting script. - github-archive-old-repos.sh: changed its REPORT_DIR default from a script-directory-relative path to ./reports for consistency with the rest of the fleet (still overridable). - github-get-repo-list.sh: fixed a bug where it silently wrote to ./repo-list.csv in the working directory instead of stdout, despite its own header, README, and action.yml all documenting stdout output. Updated README.md, action.yml inputs, and script header comments to document REPORT_DIR everywhere it now applies. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 2bca0ea commit 9de57d0

9 files changed

Lines changed: 52 additions & 13 deletions

File tree

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ cd org-admin/github-archive-old-repos
330330
| Variable | Description | Default |
331331
|----------|-------------|---------|
332332
| `YEARS_THRESHOLD` | Age threshold in years | `5` |
333+
| `REPORT_DIR` | Output directory for the CSV report | `./reports` |
333334

334335
---
335336

@@ -409,6 +410,7 @@ cd org-admin/github-close-archived-repo-security-alerts
409410
| `DEPENDABOT_REASON` | Dismiss reason for Dependabot alerts | `tolerable_risk` |
410411
| `CODE_SCANNING_REASON` | Dismiss reason for code scanning alerts | `won't fix` |
411412
| `SECRET_SCANNING_RESOLUTION` | Resolution for secret scanning alerts | `wont_fix` |
413+
| `REPORT_DIR` | Output directory for the CSV report | `./reports` |
412414

413415
**What it does:**
414416
- Enumerates all repositories in the organization
@@ -561,7 +563,11 @@ cd reporting/github-repo-permissions-report
561563
|------|-------------|----------|
562564
| `-r, --repo OWNER/REPO` | Target repository (required) ||
563565
| `-b, --branch NAME` | Branch to evaluate | Repository default branch |
564-
| `-o, --output FILE` | Output CSV path | `OWNER-REPO-permissions-BRANCH-YYYYMMDD.csv` |
566+
| `-o, --output FILE` | Output CSV path | `$REPORT_DIR/OWNER-REPO-permissions-BRANCH-YYYYMMDD.csv` |
567+
568+
| Variable | Description | Default |
569+
|----------|-------------|---------|
570+
| `REPORT_DIR` | Output directory for the CSV report when `-o/--output` is not given | `./reports` |
565571

566572
**What it does:**
567573
- Fetches all collaborators and teams with repository access
@@ -617,10 +623,14 @@ az login # optional; needed only for Entra ID department enrichment
617623
| `-e, --enterprise SLUG` | GitHub Enterprise slug (or `$GITHUB_ENTERPRISE`) ||
618624
| `-d, --upn-domain DOM` | Email domain for Entra lookup when GitHub carries no email (or `$UPN_DOMAIN`) ||
619625
| `--credits N` | Override credits-per-seat value (or `$CREDITS_PER_SEAT_OVERRIDE`) | Auto-detected |
620-
| `--output FILE` | Output CSV filename | `copilot-report-YYYYMMDD.csv` |
626+
| `--output FILE` | Output CSV filename | `$REPORT_DIR/copilot-report-YYYYMMDD.csv` |
621627
| `--no-entra` | Skip Entra ID department lookup ||
622628
| `--no-budgets` | Skip per-user AI credit budget lookup (Universal/Individual) ||
623629

630+
| Variable | Description | Default |
631+
|----------|-------------|---------|
632+
| `REPORT_DIR` | Output directory for the CSV report when `--output` is not given | `./reports` |
633+
624634
**What it does:**
625635
- Fetches all Copilot seats across the enterprise (deduplicated by user)
626636
- Fetches per-user AI credit consumption for the current billing month

org-admin/github-archive-old-repos/github-archive-old-repos.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# GITHUB_TOKEN Required. PAT with repo scope
1616
# ORG Required. GitHub organization name
1717
# YEARS_THRESHOLD Optional. Age threshold in years (default: 5)
18+
# REPORT_DIR Optional. Output directory for the CSV report (default: ./reports)
1819
# API_URL_PREFIX Optional. GitHub API base URL (default: https://api.github.com)
1920
#
2021
# Requirements:
@@ -36,7 +37,7 @@ ORG=${ORG:-''}
3637
API_URL_PREFIX=${API_URL_PREFIX:-'https://api.github.com'}
3738
YEARS_THRESHOLD=${YEARS_THRESHOLD:-5}
3839
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
39-
REPORT_DIR="${REPORT_DIR:-$(dirname "$0")/reports}"
40+
REPORT_DIR="${REPORT_DIR:-./reports}"
4041
REPORT_FILE="${REPORT_DIR}/old_repos_${TIMESTAMP}.csv"
4142
TEMP_FILE=$(mktemp)
4243

org-admin/github-close-archived-repo-security-alerts/action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ inputs:
3131
description: 'GitHub API base URL'
3232
required: false
3333
default: 'https://api.github.com'
34+
report-dir:
35+
description: 'Output directory for the CSV report'
36+
required: false
37+
default: './reports'
3438
runs:
3539
using: composite
3640
steps:
@@ -43,6 +47,7 @@ runs:
4347
CODE_SCANNING_REASON: ${{ inputs.code-scanning-reason }}
4448
SECRET_SCANNING_RESOLUTION: ${{ inputs.secret-scanning-resolution }}
4549
API_URL_PREFIX: ${{ inputs.api-url-prefix }}
50+
REPORT_DIR: ${{ inputs.report-dir }}
4651
run: |
4752
ARGS=(--type "${{ inputs.type }}")
4853
[[ "${{ inputs.dry-run }}" == "true" ]] && ARGS+=(--dry-run)

org-admin/github-close-archived-repo-security-alerts/github-close-archived-repo-security-alerts.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
# DEPENDABOT_REASON Optional. Dismiss reason for Dependabot alerts (default: tolerable_risk)
2222
# CODE_SCANNING_REASON Optional. Dismiss reason for code scanning (default: won't fix)
2323
# SECRET_SCANNING_RESOLUTION Optional. Resolution for secret scanning (default: wont_fix)
24+
# REPORT_DIR Optional. Output directory for the CSV report (default: ./reports)
2425
#
2526
# Requirements:
2627
# - curl
@@ -40,8 +41,8 @@ GITHUB_TOKEN=${GITHUB_TOKEN:-''}
4041
ORG=${ORG:-''}
4142
API_URL_PREFIX=${API_URL_PREFIX:-'https://api.github.com'}
4243
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
43-
REPORTS_DIR="$(dirname "$0")/reports"
44-
REPORT_FILE="${REPORTS_DIR}/security_alerts_closed_${TIMESTAMP}.csv"
44+
REPORT_DIR="${REPORT_DIR:-./reports}"
45+
REPORT_FILE="${REPORT_DIR}/security_alerts_closed_${TIMESTAMP}.csv"
4546

4647
# Dismiss/resolve reasons — override via env if needed
4748
DEPENDABOT_REASON=${DEPENDABOT_REASON:-'tolerable_risk'} # fix_started | inaccurate | no_bandwidth | not_used | tolerable_risk
@@ -117,7 +118,7 @@ TOTAL_ERRORS=0
117118
## CSV REPORT HEADER
118119
###
119120
if [ "${DRY_RUN}" = false ]; then
120-
mkdir -p "${REPORTS_DIR}"
121+
mkdir -p "${REPORT_DIR}"
121122
echo "timestamp,org,repo,alert_type,alert_number,alert_summary,action" > "${REPORT_FILE}"
122123
fi
123124

org-admin/github-get-repo-list/github-get-repo-list.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,10 @@ process_repos () {
7575

7676
printf '%s,%s,%s,%s,%s,"%s",%s,%s,%s,%s\n' \
7777
"${i}" "${REPO_FULLNAME}" "${REPO_OWNER}" "${REPO_PRIVATE}" "${REPO_HTMLURL}" \
78-
"${ESCAPED_DESCRIPTION}" "${REPO_FORK}" "${REPO_PUSHEDAT}" "${REPO_CREATEDAT}" "${REPO_UPDATEDAT}" \
79-
>> repo-list.csv
78+
"${ESCAPED_DESCRIPTION}" "${REPO_FORK}" "${REPO_PUSHEDAT}" "${REPO_CREATEDAT}" "${REPO_UPDATEDAT}"
8079
done < <(echo "${repos_json}" | jq -r 'sort_by(.name) | .[] | .name')
8180
done
8281
}
8382

84-
echo "name,full_name,owner,private,html_url,description,fork,pushed_at,created_at,updated_at" > repo-list.csv
83+
echo "name,full_name,owner,private,html_url,description,fork,pushed_at,created_at,updated_at"
8584
process_repos

reporting/github-copilot-report/action.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@ inputs:
2020
required: false
2121
default: ''
2222
output:
23-
description: 'Output CSV file path (default: copilot-report-YYYYMMDD.csv)'
23+
description: 'Output CSV file path (default: $REPORT_DIR/copilot-report-YYYYMMDD.csv)'
2424
required: false
2525
default: ''
26+
report-dir:
27+
description: 'Output directory for the CSV report when output is not given'
28+
required: false
29+
default: './reports'
2630
no-entra:
2731
description: 'Skip Entra ID department lookup'
2832
required: false
@@ -42,6 +46,7 @@ runs:
4246
UPN_DOMAIN: ${{ inputs.upn-domain }}
4347
ENTRA_TENANT: ${{ inputs.entra-tenant }}
4448
CREDITS_PER_SEAT_OVERRIDE: ${{ inputs.credits }}
49+
REPORT_DIR: ${{ inputs.report-dir }}
4550
run: |
4651
ARGS=()
4752
[[ -n "${{ inputs.output }}" ]] && ARGS+=(--output "${{ inputs.output }}")

reporting/github-copilot-report/github-copilot-report.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545
# amount plus an override_budget_id when an Individual budget applies.
4646
# Requires the token owner to be an enterprise admin or billing manager.
4747
# Use --no-budgets to skip.
48+
#
49+
# REPORT_DIR (optional, default: ./reports) — output directory for the CSV
50+
# report when --output is not given.
4851
# =============================================================================
4952

5053
set -euo pipefail
@@ -60,7 +63,8 @@ API_URL_PREFIX="${API_URL_PREFIX:-https://api.github.com}"
6063
UPN_DOMAIN="${UPN_DOMAIN:-}"
6164
ENTRA_TENANT="${ENTRA_TENANT:-}"
6265
CREDITS_PER_SEAT_OVERRIDE="${CREDITS_PER_SEAT_OVERRIDE:-}"
63-
OUTPUT_CSV="copilot-report-$(date +%Y%m%d).csv"
66+
REPORT_DIR="${REPORT_DIR:-./reports}"
67+
OUTPUT_CSV=""
6468
NO_ENTRA=false
6569
NO_BUDGETS=false
6670
GRAPH_TOKEN=""
@@ -127,7 +131,7 @@ Options:
127131
when not set; only needed to override that result.
128132
--credits N Override credits-per-seat value (or $CREDITS_PER_SEAT_OVERRIDE)
129133
Use if your portal shows a different pool size than expected
130-
--output FILE Output CSV (default: copilot-report-YYYYMMDD.csv)
134+
--output FILE Output CSV (default: $REPORT_DIR/copilot-report-YYYYMMDD.csv)
131135
--no-entra Skip Entra ID department lookup
132136
--no-budgets Skip per-user AI credit budget lookup (Universal/Individual)
133137
-h, --help Show this message
@@ -165,6 +169,11 @@ require_command jq
165169
require_env_var GITHUB_TOKEN
166170
validate_github_token "bearer"
167171

172+
if [[ -z "$OUTPUT_CSV" ]]; then
173+
mkdir -p "$REPORT_DIR"
174+
OUTPUT_CSV="${REPORT_DIR}/copilot-report-$(date +%Y%m%d).csv"
175+
fi
176+
168177
# ── Acquire Microsoft Graph token via az CLI ──────────────────────────────────
169178
if [[ "$NO_ENTRA" == "true" ]]; then
170179
print_warning "Entra ID lookup disabled (--no-entra). Department column will be N/A."

reporting/github-repo-permissions-report/action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,18 @@ inputs:
1515
description: 'Output CSV file path'
1616
required: false
1717
default: ''
18+
report-dir:
19+
description: 'Output directory for the CSV report when output is not given'
20+
required: false
21+
default: './reports'
1822
runs:
1923
using: composite
2024
steps:
2125
- name: Generate repository permissions report
2226
shell: bash
2327
env:
2428
GITHUB_TOKEN: ${{ inputs.github-token || github.token }}
29+
REPORT_DIR: ${{ inputs.report-dir }}
2530
run: |
2631
ARGS=(-r "${{ inputs.repo }}")
2732
[[ -n "${{ inputs.branch }}" ]] && ARGS+=(-b "${{ inputs.branch }}")

reporting/github-repo-permissions-report/github-repo-permissions-report.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
# GITHUB_TOKEN Required. PAT with repo and read:org scope
1515
# (or provided automatically from an active gh auth session)
1616
# API_URL_PREFIX Optional. GitHub API base URL (default: https://api.github.com)
17+
# REPORT_DIR Optional. Output directory for the CSV report when -o/--output
18+
# is not given (default: ./reports)
1719
#
1820
# Requirements:
1921
# - curl
@@ -27,6 +29,7 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
2729
source "${SCRIPT_DIR}/../../lib/github-common.sh"
2830

2931
API_URL_PREFIX=${API_URL_PREFIX:-'https://api.github.com'}
32+
REPORT_DIR=${REPORT_DIR:-'./reports'}
3033
REPO=""
3134
BRANCH=""
3235
OUTPUT_CSV=""
@@ -104,7 +107,8 @@ if [[ -z "$BRANCH" ]]; then
104107
fi
105108

106109
if [[ -z "$OUTPUT_CSV" ]]; then
107-
OUTPUT_CSV="${REPO//\//-}-permissions-${BRANCH}-$(date +%Y%m%d).csv"
110+
mkdir -p "$REPORT_DIR"
111+
OUTPUT_CSV="${REPORT_DIR}/${REPO//\//-}-permissions-${BRANCH}-$(date +%Y%m%d).csv"
108112
fi
109113

110114
print_status "Fetching collaborators..."

0 commit comments

Comments
 (0)