|
| 1 | +<!-- toc --> |
| 2 | + |
| 3 | +- [`TutorialsTask76_automate_collaborator_invitations_from_gsheet.py` Explanation](#tutorialstask76_automate_collaborator_invitations_from_gsheetpy-explanation) |
| 4 | + * [Public interface](#public-interface) |
| 5 | + * [Execution flow](#execution-flow) |
| 6 | + * [Key implementation choices](#key-implementation-choices) |
| 7 | + |
| 8 | +<!-- tocstop --> |
| 9 | + |
| 10 | +# `TutorialsTask76_automate_collaborator_invitations_from_gsheet.py` Explanation |
| 11 | + |
| 12 | +This document is about how this script works and flows. |
| 13 | + |
| 14 | +## Public interface |
| 15 | + |
| 16 | +```bash |
| 17 | +TutorialsTask76_automate_collaborator_invitations_from_gsheet.py \ |
| 18 | + --drive_url <google‑sheet‑url> \ |
| 19 | + --gh_token <github‑pat> \ |
| 20 | + --org_name <github‑org> \ |
| 21 | + --repo_name <repo> \ |
| 22 | + [--log_level 20] |
| 23 | +``` |
| 24 | + |
| 25 | +- **`drive_url`** – Spreadsheet containing a `GitHub user` column. |
| 26 | +- **`gh_token`** – PAT with `repo` scope (or fine‑grained "Repository |
| 27 | + administration"). |
| 28 | +- **`org_name` / `repo_name`** – identify the target repository. |
| 29 | +- **`log_level`** – standard Python numeric levels (10 = DEBUG, 20 = INFO). |
| 30 | + |
| 31 | +The module can also be imported: |
| 32 | + |
| 33 | +```python |
| 34 | +import DATA605.TutorialsTask76_automate_collaborator_invitations_from_gsheet as dtacifrgs |
| 35 | +usernames = dtacifrgs.extract_usernames_from_gsheet(sheet_url) |
| 36 | +dtacifrgs.send_invitations(usernames, token, repo, org) |
| 37 | +``` |
| 38 | + |
| 39 | +## Execution flow |
| 40 | + |
| 41 | +```mermaid |
| 42 | +flowchart TD |
| 43 | + A[parse CLI args] --> B[init logging] |
| 44 | + B --> C[extract_usernames_from_gsheet] |
| 45 | + C -->|"list[str]"| D[send_invitations] |
| 46 | + D --> E{already collaborator?} |
| 47 | + E -- yes --> F[skip + log] |
| 48 | + E -- no --> G[_invite wrapper] |
| 49 | + G -->|add_to_collaborators| H[GitHub API] |
| 50 | + subgraph Rate-limit |
| 51 | + direction TB |
| 52 | + G |
| 53 | + note("@ratelimit.limits 50 calls / 24h → sleep_and_retry if exceeded") |
| 54 | + end |
| 55 | +``` |
| 56 | + |
| 57 | +## Key implementation choices |
| 58 | + |
| 59 | +- **Dependency auto‑install** – the small `pip install` loop avoids a separate |
| 60 | + requirements file when the script runs in fresh environments, at the cost of |
| 61 | + start‑up time. |
| 62 | +- **Service‑account auth** – credentials path is hard‑coded but can be fed via |
| 63 | + env‑var if desired; the helper supports both. |
| 64 | +- **Idempotence** – `repo.has_in_collaborators()` prevents duplicate invites |
| 65 | + counting toward the daily quota. |
| 66 | +- **Sleep strategy** – we rely entirely on `ratelimit.sleep_and_retry`, so the |
| 67 | + process may block for hours. Even if the process is terminated, the |
| 68 | + idempotence measure will prevent the added names from contributing to the |
| 69 | + quota |
0 commit comments