generateRateLimitCheck generates steps for rate limiting check
(data *WorkflowData, steps []string)
| 47 | |
| 48 | // generateRateLimitCheck generates steps for rate limiting check |
| 49 | func (c *Compiler) generateRateLimitCheck(data *WorkflowData, steps []string) []string { |
| 50 | steps = append(steps, " - name: Check user rate limit\n") |
| 51 | steps = append(steps, fmt.Sprintf(" id: %s\n", constants.CheckRateLimitStepID)) |
| 52 | steps = append(steps, fmt.Sprintf(" uses: %s\n", getCachedActionPin("actions/github-script", data))) |
| 53 | |
| 54 | // Add environment variables for rate limit check |
| 55 | steps = append(steps, " env:\n") |
| 56 | |
| 57 | // Set max (default: 5) |
| 58 | max := constants.DefaultRateLimitMax |
| 59 | if data.RateLimit.Max > 0 { |
| 60 | max = data.RateLimit.Max |
| 61 | } |
| 62 | steps = append(steps, fmt.Sprintf(" GH_AW_RATE_LIMIT_MAX: \"%d\"\n", max)) |
| 63 | |
| 64 | // Set window (default: 60 minutes) |
| 65 | window := constants.DefaultRateLimitWindow |
| 66 | if data.RateLimit.Window > 0 { |
| 67 | window = data.RateLimit.Window |
| 68 | } |
| 69 | steps = append(steps, fmt.Sprintf(" GH_AW_RATE_LIMIT_WINDOW: \"%d\"\n", window)) |
| 70 | |
| 71 | // Set events to check (if specified) |
| 72 | if len(data.RateLimit.Events) > 0 { |
| 73 | // Sort events alphabetically for consistent output |
| 74 | events := make([]string, len(data.RateLimit.Events)) |
| 75 | copy(events, data.RateLimit.Events) |
| 76 | sort.Strings(events) |
| 77 | steps = append(steps, fmt.Sprintf(" GH_AW_RATE_LIMIT_EVENTS: %q\n", strings.Join(events, ","))) |
| 78 | } |
| 79 | |
| 80 | // Set ignored roles (if specified) |
| 81 | if len(data.RateLimit.IgnoredRoles) > 0 { |
| 82 | // Sort roles alphabetically for consistent output |
| 83 | ignoredRoles := make([]string, len(data.RateLimit.IgnoredRoles)) |
| 84 | copy(ignoredRoles, data.RateLimit.IgnoredRoles) |
| 85 | sort.Strings(ignoredRoles) |
| 86 | steps = append(steps, fmt.Sprintf(" GH_AW_RATE_LIMIT_IGNORED_ROLES: %q\n", strings.Join(ignoredRoles, ","))) |
| 87 | } |
| 88 | |
| 89 | steps = append(steps, " with:\n") |
| 90 | steps = append(steps, " github-token: ${{ secrets.GITHUB_TOKEN }}\n") |
| 91 | steps = append(steps, " script: |\n") |
| 92 | steps = append(steps, generateGitHubScriptWithRequire("check_rate_limit.cjs")) |
| 93 | |
| 94 | return steps |
| 95 | } |
| 96 | |
| 97 | // extractLabelNames extracts the 'labels' field from frontmatter. |
| 98 | // When set, the pre-activation job emits a job-level if: condition that skips the workflow |
no test coverage detected