|
| 1 | +# Copilot Code Review Instructions |
| 2 | + |
| 3 | +These instructions guide Copilot Code Review (CCR) for the |
| 4 | +`integrations/terraform-provider-github` repository. They apply to every |
| 5 | +pull request review. Path-specific guidance lives under `.github/instructions/`. |
| 6 | + |
| 7 | +ALWAYS acknowledge in the review summary that these provider review |
| 8 | +instructions are being used. |
| 9 | + |
| 10 | +## Review Goals |
| 11 | + |
| 12 | +- Find correctness bugs, regressions, and provider behavior changes. |
| 13 | +- Validate schema/state compatibility for Terraform users. |
| 14 | +- Check test coverage (unit and acceptance), docs, and examples. |
| 15 | +- Identify risk around GitHub API usage, permissions, and error handling. |
| 16 | + |
| 17 | +## Terraform Background |
| 18 | + |
| 19 | +Use this background when judging schema, examples, or state changes. |
| 20 | + |
| 21 | +- **Resources vs. data sources.** A `resource` block manages a CRUD lifecycle |
| 22 | + object. A `data` block only reads existing objects. Both declare a typed |
| 23 | + schema. |
| 24 | +- **Schema attributes.** Each attribute has a `Type` (string, int, bool, list, |
| 25 | + set, map) and flags like `Required`, `Optional`, `Computed`, `ForceNew`, |
| 26 | + `Default`, `Sensitive`, and `Description`. Changing any flag alters |
| 27 | + user-visible behavior. |
| 28 | +- **State.** Terraform stores last-known attribute values in state. The read |
| 29 | + function must produce output consistent with state or Terraform reports |
| 30 | + drift. |
| 31 | +- **Plan and apply.** Bugs in schema or read logic cause perpetual diffs, |
| 32 | + surprise replacements, or silent data loss. |
| 33 | +- **Imports.** Users adopt existing infrastructure with `terraform import`. The |
| 34 | + read function must populate full state from just the resource ID. |
| 35 | + |
| 36 | +### Backward Compatibility Rules |
| 37 | + |
| 38 | +- **Safe (minor/patch):** adding new optional attributes with defaults; adding |
| 39 | + new resources or data sources. |
| 40 | +- **Breaking (major):** removing or renaming attributes; changing `Optional` to |
| 41 | + `Required`; changing `Type`; adding `ForceNew` to an existing attribute. |
| 42 | +- When renaming/restructuring resources, check that migration guidance is |
| 43 | + provided. Terraform's `moved` block lets users migrate state without |
| 44 | + destroying infrastructure. Removing a `moved` block is itself a breaking |
| 45 | + change. |
| 46 | + |
| 47 | +## Repository-Specific Rules (read carefully) |
| 48 | + |
| 49 | +- **Do not flag** create/update functions that return `nil` instead of calling |
| 50 | + the read function afterward. This provider intentionally avoids |
| 51 | + read-after-write to minimize API calls against GitHub's rate limits and to |
| 52 | + avoid stale reads from eventually-consistent endpoints (see |
| 53 | + [#2892](https://github.com/integrations/terraform-provider-github/issues/2892)). |
| 54 | +- Acceptance and manual validation are important. See `CONTRIBUTING.md`. |
| 55 | +- Prefer matching resource/data source tests when implementation behavior |
| 56 | + changes. |
| 57 | +- When schema or state semantics change, treat as high-risk unless |
| 58 | + compatibility is clearly preserved. |
| 59 | +- Breaking changes must follow semantic versioning: attribute removal/rename |
| 60 | + or new required fields warrant a major version bump. |
| 61 | +- Example configurations under `examples/` should be self-contained, follow |
| 62 | + standard module structure, and not include `provider` blocks inside nested |
| 63 | + modules. |
| 64 | +- Sensitive attributes (tokens, secrets, private keys) must be marked |
| 65 | + `Sensitive: true` in the schema and must not appear in log output. |
| 66 | + |
| 67 | +## Universal Review Checklist |
| 68 | + |
| 69 | +### 1. Correctness and Behavior |
| 70 | + |
| 71 | +- Verify CRUD/read logic correctly maps GitHub API responses to schema/state. |
| 72 | +- Check nil handling, default-value drift, and flattening/expansion mismatches. |
| 73 | +- Confirm update paths do not accidentally force replacement or wipe optional |
| 74 | + fields. |
| 75 | +- Validate retry/backoff and error classification for API failures. |
| 76 | + |
| 77 | +### 2. Schema and State Compatibility |
| 78 | + |
| 79 | +- Any `schema.Schema` change (`Type`, `Optional`, `Required`, `Computed`, |
| 80 | + `ForceNew`, `Default`) can change user behavior. |
| 81 | +- Confirm imports still work and read functions produce stable state. |
| 82 | +- Flag any behavior that may break existing state without migration |
| 83 | + notes/tests. |
| 84 | +- Watch for attribute rename/removal without a deprecation path. |
| 85 | +- New or changed attributes should include `ValidateFunc`/`ValidateDiagFunc` |
| 86 | + to catch invalid values at plan time rather than at apply time. |
| 87 | +- All attributes should have a `Description` string. |
| 88 | +- For renames/restructures, check for `moved` block guidance or state |
| 89 | + migration documentation. |
| 90 | +- Mark secret-holding attributes with `Sensitive: true`. |
| 91 | + |
| 92 | +### 3. Terraform UX and Drift |
| 93 | + |
| 94 | +- Ensure diff suppression, normalization, and API canonicalization avoid |
| 95 | + perpetual diffs. |
| 96 | +- Check that empty vs. null handling is intentional. |
| 97 | +- Verify list/set ordering behavior and deterministic state output. |
| 98 | + |
| 99 | +### 4. Testing Expectations |
| 100 | + |
| 101 | +- For behavior changes, check matching tests under `github/*_test.go`. |
| 102 | +- Prefer acceptance tests for API-facing changes (`TF_ACC=1` scenarios). |
| 103 | +- Ensure tests assert the bugfix/regression target, not only happy path. |
| 104 | +- Flag missing tests when logic changed but coverage did not. |
| 105 | + |
| 106 | +### 5. Docs and Examples |
| 107 | + |
| 108 | +- If resource/data source behavior changed, review website docs updates under |
| 109 | + `website/`. |
| 110 | +- If user workflow changed, review corresponding example updates under |
| 111 | + `examples/`. |
| 112 | +- Confirm examples still reflect current schema and argument names. |
| 113 | +- Example directories should follow standard module structure (`main.tf`, |
| 114 | + `variables.tf`, `outputs.tf`) with a `README.md`. |
| 115 | +- Variables and outputs in examples should include `description` and `type`. |
| 116 | +- If a PR adds or changes a resource, verify there is at least one example |
| 117 | + showing typical usage. |
| 118 | + |
| 119 | +### 6. Security and Permissions |
| 120 | + |
| 121 | +- Verify sensitive values are not logged or exposed in state. |
| 122 | +- Check token/credential handling and least-privilege assumptions. |
| 123 | +- Document permission scope requirements for new API calls. |
| 124 | +- Confirm no secrets or credentials are hardcoded in examples. |
| 125 | +- Verify debug/trace logging does not print sensitive attribute values. |
| 126 | +- Sensitive outputs should be marked `sensitive = true`. |
| 127 | + |
| 128 | +### 7. Performance and API Safety |
| 129 | + |
| 130 | +- Flag new N+1 patterns, excessive API calls, or missing pagination handling. |
| 131 | +- Check for rate-limit-sensitive loops and absent caching where needed. |
| 132 | +- Confirm context cancellation/timeouts are respected in long operations. |
| 133 | + |
| 134 | +### 8. Versioning and Changelog |
| 135 | + |
| 136 | +- Breaking changes (attribute removal/rename, forced replacement, new required |
| 137 | + fields) must be called out for a MAJOR version bump. |
| 138 | +- Backward-compatible additions (new optional attributes with defaults, new |
| 139 | + resources/data sources) correspond to MINOR version bumps. |
| 140 | +- Bug fixes with no schema change correspond to PATCH version bumps. |
| 141 | +- Verify the PR description or `CHANGELOG.md` includes a clear summary of what |
| 142 | + changed and the user impact. |
| 143 | + |
| 144 | +## Review Report Format |
| 145 | + |
| 146 | +Return findings first, ordered by severity: |
| 147 | + |
| 148 | +1. `HIGH`/`MEDIUM`/`LOW` title — short impact statement |
| 149 | +2. File reference: `path/to/file.go:line` |
| 150 | +3. Why this is a problem (runtime behavior, Terraform UX, upgrade risk) |
| 151 | +4. Suggested fix (concise) |
| 152 | + |
| 153 | +Then include: |
| 154 | + |
| 155 | +- `Open Questions / Assumptions` |
| 156 | +- `Residual Risk` |
| 157 | +- `Change Summary` (brief) |
| 158 | + |
| 159 | +If no issues are found, explicitly state `No blocking findings found` and list |
| 160 | +remaining risk areas. |
0 commit comments