|
| 1 | +# GitHub Approval Automation |
| 2 | + |
| 3 | +This module contains the `ApprovalManager` class used by GitHub Actions workflows to automate the approval process for pipeline proposals and RFCs. |
| 4 | + |
| 5 | +## Files |
| 6 | + |
| 7 | +- `approval.js` - The main ApprovalManager class |
| 8 | +- `approval.test.js` - Unit tests for ApprovalManager class |
| 9 | +- `workflow-integration.test.js` - Integration tests for complete workflow scenarios |
| 10 | +- `package.json` - Node.js package configuration with Jest setup |
| 11 | +- `README.md` - This documentation file |
| 12 | + |
| 13 | +## ApprovalManager Class |
| 14 | + |
| 15 | +The `ApprovalManager` class handles: |
| 16 | + |
| 17 | +- Fetching team members from GitHub organization teams |
| 18 | +- Processing comments to track approvals and rejections via `/approve` and `/reject` commands |
| 19 | +- Updating issue status and labels based on approval state |
| 20 | +- Managing status comments on issues |
| 21 | + |
| 22 | +### Usage Scenarios |
| 23 | + |
| 24 | +#### Pipeline Proposals |
| 25 | + |
| 26 | +- **Approval Criteria**: Either 2 core team members OR 1 core team member + 1 maintainer |
| 27 | +- **Issue Title Pattern**: Must start with "New Pipeline" |
| 28 | +- **Team Roles**: Both core team and maintainers can vote |
| 29 | + |
| 30 | +#### RFC Proposals |
| 31 | + |
| 32 | +- **Approval Criteria**: Quorum of core team members (Math.ceil(coreTeamMembers.length / 2)) |
| 33 | +- **Issue Title Pattern**: Must start with "New RFC" |
| 34 | +- **Team Roles**: Only core team members can vote |
| 35 | + |
| 36 | +## Running Tests |
| 37 | + |
| 38 | +### Prerequisites |
| 39 | + |
| 40 | +Install Node.js and npm, then install Jest: |
| 41 | + |
| 42 | +```bash |
| 43 | +npm install |
| 44 | +``` |
| 45 | + |
| 46 | +### Test Commands |
| 47 | + |
| 48 | +```bash |
| 49 | +# Run all tests |
| 50 | +npm test |
| 51 | + |
| 52 | +# Run tests in watch mode (reruns on file changes) |
| 53 | +npm test:watch |
| 54 | + |
| 55 | +# Run tests with coverage report |
| 56 | +npm test:coverage |
| 57 | +``` |
| 58 | + |
| 59 | +## Test Suite |
| 60 | + |
| 61 | +The test suite includes both unit tests and integration tests: |
| 62 | + |
| 63 | +### Unit Tests (`approval.test.js`) |
| 64 | + |
| 65 | +Tests individual methods and functionality of the ApprovalManager class. |
| 66 | + |
| 67 | +### Integration Tests (`workflow-integration.test.js`) |
| 68 | + |
| 69 | +End-to-end tests that simulate complete workflow scenarios as they would run in GitHub Actions. |
| 70 | + |
| 71 | +## Test Coverage |
| 72 | + |
| 73 | +The combined test suites cover: |
| 74 | + |
| 75 | +### Core Functionality |
| 76 | + |
| 77 | +- ✅ Constructor initialization |
| 78 | +- ✅ Team member fetching from GitHub API |
| 79 | +- ✅ Comment processing with `/approve` and `/reject` commands |
| 80 | +- ✅ Status comment updates |
| 81 | +- ✅ Issue label management |
| 82 | + |
| 83 | +### Pipeline Proposal Scenarios |
| 84 | + |
| 85 | +- ✅ Approval with 2 core members |
| 86 | +- ✅ Approval with 1 core + 1 maintainer |
| 87 | +- ✅ No approval with only 1 core member |
| 88 | +- ✅ No approval with only maintainers |
| 89 | + |
| 90 | +### RFC Proposal Scenarios |
| 91 | + |
| 92 | +- ✅ Approval with core team quorum |
| 93 | +- ✅ No approval without quorum |
| 94 | +- ✅ Quorum calculation for different team sizes |
| 95 | +- ✅ Ignoring maintainer votes (core-only) |
| 96 | + |
| 97 | +### Edge Cases |
| 98 | + |
| 99 | +- ✅ Case-insensitive commands (`/APPROVE`, `/reject`) |
| 100 | +- ✅ Commands only at start of line |
| 101 | +- ✅ Multiple commands from same user |
| 102 | +- ✅ Multiple commands within same comment |
| 103 | +- ✅ Non-team member comments (ignored) |
| 104 | +- ✅ Empty or malformed comments |
| 105 | +- ✅ Mixed line endings |
| 106 | +- ✅ Users in both core and maintainer teams |
| 107 | + |
| 108 | +### Error Handling |
| 109 | + |
| 110 | +- ✅ GitHub API errors |
| 111 | +- ✅ Empty comment arrays |
| 112 | +- ✅ Null/undefined comment bodies |
| 113 | +- ✅ Malformed regex patterns |
| 114 | + |
| 115 | +## Command Format |
| 116 | + |
| 117 | +The approval system recognizes these commands when they appear at the start of a line in a comment: |
| 118 | + |
| 119 | +- `/approve` - Approve the proposal |
| 120 | +- `/reject` - Reject the proposal |
| 121 | + |
| 122 | +Commands are case-insensitive and can include additional text after the command. |
| 123 | + |
| 124 | +### Examples |
| 125 | + |
| 126 | +``` |
| 127 | +/approve |
| 128 | +``` |
| 129 | + |
| 130 | +``` |
| 131 | +/approve This looks good to me! |
| 132 | +``` |
| 133 | + |
| 134 | +``` |
| 135 | +/reject |
| 136 | +This needs more work before approval. |
| 137 | +``` |
| 138 | + |
| 139 | +``` |
| 140 | +I have some concerns. |
| 141 | +/reject |
| 142 | +``` |
| 143 | + |
| 144 | +## Status Labels |
| 145 | + |
| 146 | +The system manages these issue labels: |
| 147 | + |
| 148 | +- `proposed` - Initial state for new proposals |
| 149 | +- `accepted` - Proposal has sufficient approvals |
| 150 | +- `turned-down` - Proposal was rejected |
| 151 | +- `timed-out` - Proposal expired without sufficient votes |
0 commit comments