|
| 1 | +## Co-Authors support |
| 2 | + |
| 3 | +You can allow co-authors support on a specific repository, set of repositories matching regular expression pattern, or for all repositories in a GitHub organization. |
| 4 | + |
| 5 | +This can be done on the GitHub organization level by setting the `enable_co_authors` property on `cla-{stage}-github-orgs` DynamoDB table. |
| 6 | + |
| 7 | +Replace `{stage}` with either `dev` or `prod`. |
| 8 | + |
| 9 | +This property is a map attribute that contains mapping from repository pattern to co-authors support enabled or disabled. |
| 10 | + |
| 11 | +So the format is like `"repository_pattern": true|false`. |
| 12 | + |
| 13 | +There can be multiple entries under one Github Organization DynamoDB entry. |
| 14 | + |
| 15 | +Example: |
| 16 | +``` |
| 17 | +{ |
| 18 | +(...) |
| 19 | + "organization_name": { |
| 20 | + "S": "linuxfoundation" |
| 21 | + }, |
| 22 | + "enable_co_authors": { |
| 23 | + "M": { |
| 24 | + "*": { |
| 25 | + "BOOL": true, |
| 26 | + }, |
| 27 | + "re:(?i)^repo[0-9]+$": { |
| 28 | + "BOOL": false, |
| 29 | + } |
| 30 | + } |
| 31 | + }, |
| 32 | +(...) |
| 33 | +} |
| 34 | +``` |
| 35 | + |
| 36 | +This enables co-authors support on all repos under "linuxfoundation", except for those matching the regular expression `re:(?i)^repo[0-9]+$`. |
| 37 | + |
| 38 | +Algorithm to match pattern is as follows: |
| 39 | +- First we check repository name for exact match. Repository name is without the organization name, so for `https://github.com/linuxfoundation/easycla` it is just `easycla`. If we find an entry in `enable_co_authors` for `easycla` that entry is used and we stop searching. |
| 40 | +- If no exact match is found, we check for regular expression match. Only keys starting with `re:` are considered. If we find a match, we use that entry and stop searching. |
| 41 | +- If no match is found, we check for `*` entry. If it exists, we use that entry and stop searching. |
| 42 | +- If no match is found, we don't support co-authors for that repository. Default is no co-author support. |
| 43 | + |
| 44 | + |
| 45 | +There is a script that allows you to update the `enable_co_authors` property in the DynamoDB table. It is located in `utils/enable_co_authors_entry.sh`. You can run it like this: |
| 46 | +- `` MODE=mode ./utils/enable_co_authors_entry.sh 'org-name' 'repo-pattern' t ``. |
| 47 | +- `` MODE=add-key ./utils/enable_co_authors_entry.sh 'sun-test-org' '*' f ``. |
| 48 | + |
| 49 | +`MODE` can be one of: |
| 50 | +- `put-item`: Overwrites/adds the entire `enable_co_authors` property. Needs all 3 arguments org, repo, and pattern. |
| 51 | +- `add-key`: Adds or updates a key/value inside the `enable_co_authors` map (preserves other keys). Needs all 3 args. |
| 52 | +- `delete-key`: Removes a key from the `enable_co_authors` map. Needs 2 arguments: org and repo. |
| 53 | +- `delete-item`: Deletes the entire `enable_co_authors` from the item. Needs 1 argument: org. |
| 54 | + |
| 55 | + |
| 56 | +You can also use AWS CLI to update the `enable_co_authors` property. Here is an example command: |
| 57 | + |
| 58 | +To add a new `enable_co_authors` entry: |
| 59 | + |
| 60 | +``` |
| 61 | +aws --profile "lfproduct-prod" --region "us-east-1" dynamodb update-item \ |
| 62 | + --table-name "cla-prod-github-orgs" \ |
| 63 | + --key '{"organization_name": {"S": "linuxfoundation"}}' \ |
| 64 | + --update-expression 'SET enable_co_authors = :val' \ |
| 65 | + --expression-attribute-values '{":val": {"M": {"re:^easycla":{"BOOL": true}}}}' |
| 66 | +``` |
| 67 | + |
| 68 | +To add a new key to an existing `enable_co_authors` entry (or replace the existing key): |
| 69 | + |
| 70 | +``` |
| 71 | +aws --profile "lfproduct-prod" --region "us-east-1" dynamodb update-item \ |
| 72 | + --table-name "cla-prod-github-orgs" \ |
| 73 | + --key '{"organization_name": {"S": "linuxfoundation"}}' \ |
| 74 | + --update-expression "SET enable_co_authors.#repo = :val" \ |
| 75 | + --expression-attribute-names '{"#repo": "re:^easycla"}' \ |
| 76 | + --expression-attribute-values '{":val": {"BOOL": false}}' |
| 77 | +``` |
| 78 | + |
| 79 | +To delete a key from an existing `enable_co_authors` entry: |
| 80 | + |
| 81 | +``` |
| 82 | +aws --profile "lfproduct-prod" --region "us-east-1" dynamodb update-item \ |
| 83 | + --table-name "cla-prod-github-orgs" \ |
| 84 | + --key '{"organization_name": {"S": "linuxfoundation"}}' \ |
| 85 | + --update-expression "REMOVE enable_co_authors.#repo" \ |
| 86 | + --expression-attribute-names '{"#repo": "re:^easycla"}' |
| 87 | +``` |
| 88 | + |
| 89 | +To delete the entire `enable_co_authors` entry: |
| 90 | + |
| 91 | +``` |
| 92 | +aws --profile "lfproduct-prod" --region "us-east-1" dynamodb update-item \ |
| 93 | + --table-name "cla-prod-github-orgs" \ |
| 94 | + --key '{"organization_name": {"S": "linuxfoundation"}}' \ |
| 95 | + --update-expression "REMOVE enable_co_authors" |
| 96 | +``` |
| 97 | + |
| 98 | +To see given organization's entry: `./utils/scan.sh github-orgs organization_name sun-test-org`. |
| 99 | + |
| 100 | +Or using AWS CLI: |
| 101 | + |
| 102 | +``` |
| 103 | +aws --profile "lfproduct-prod" dynamodb scan --table-name "cla-prod-github-orgs" --filter-expression "contains(organization_name,:v)" --expression-attribute-values "{\":v\":{\"S\":\"linuxfoundation\"}}" --max-items 100 | jq -r '.Items' |
| 104 | +``` |
| 105 | + |
| 106 | +To check for log entries related to skipping CLA check, you can use the following command: `` STAGE=dev DTFROM='1 hour ago' DTTO='1 second ago' ./utils/search_aws_log_group.sh 'cla-backend-dev-githubactivity' 'enable_co_authors' ``. |
| 107 | + |
| 108 | +# Example setup on prod |
| 109 | + |
| 110 | +To add first `enable_co_authors` value for an organization: |
| 111 | +``` |
| 112 | +aws --profile lfproduct-prod --region us-east-1 dynamodb update-item --table-name "cla-prod-github-orgs" --key '{"organization_name": {"S": "open-telemetry"}}' --update-expression 'SET enable_co_authors = :val' --expression-attribute-values '{":val": {"M": {"otel-arrow":{"BOOL":true}}}}' |
| 113 | +aws --profile lfproduct-prod --region us-east-1 dynamodb update-item --table-name "cla-prod-github-orgs" --key '{"organization_name": {"S": "openfga"}}' --update-expression 'SET enable_co_authors = :val' --expression-attribute-values '{":val": {"M": {"vscode-ext":{"BOOL":true}}}}' |
| 114 | +``` |
| 115 | + |
| 116 | +To add additional repositories entries without overwriting the existing `enable_co_authors` value: |
| 117 | +``` |
| 118 | +aws --profile lfproduct-prod --region us-east-1 dynamodb update-item --table-name "cla-prod-github-orgs" --key '{"organization_name": {"S": "open-telemetry"}}' --update-expression 'SET enable_co_authors.#repo = :val' --expression-attribute-names '{"#repo": "*"}' --expression-attribute-values '{":val": {"BOOL": true}}' |
| 119 | +aws --profile lfproduct-prod --region us-east-1 dynamodb update-item --table-name "cla-prod-github-orgs" --key '{"organization_name": {"S": "openfga"}}' --update-expression 'SET enable_co_authors.#repo = :val' --expression-attribute-names '{"#repo": "*"}' --expression-attribute-values '{":val": {"BOOL": true}}' |
| 120 | +``` |
| 121 | + |
| 122 | +To delete a specific repo entry from `enable_co_authors`: |
| 123 | +``` |
| 124 | +aws --profile "lfproduct-prod" --region "us-east-1" dynamodb update-item --table-name "cla-prod-github-orgs" --key '{"organization_name": {"S": "open-telemetry"}}' --update-expression 'REMOVE enable_co_authors.#repo' --expression-attribute-names '{"#repo": "*"}' |
| 125 | +aws --profile "lfproduct-prod" --region "us-east-1" dynamodb update-item --table-name "cla-prod-github-orgs" --key '{"organization_name": {"S": "openfga"}}' --update-expression 'REMOVE enable_co_authors.#repo' --expression-attribute-names '{"#repo": "*"}' |
| 126 | +``` |
| 127 | + |
| 128 | +To delete the entire `enable_co_authors` attribute: |
| 129 | +``` |
| 130 | +aws --profile "lfproduct-prod" --region "us-east-1" dynamodb update-item --table-name "cla-prod-github-orgs" --key '{"organization_name": {"S": "open-telemetry"}}' --update-expression 'REMOVE enable_co_authors' |
| 131 | +aws --profile "lfproduct-prod" --region "us-east-1" dynamodb update-item --table-name "cla-prod-github-orgs" --key '{"organization_name": {"S": "openfga"}}' --update-expression 'REMOVE enable_co_authors' |
| 132 | +``` |
| 133 | + |
| 134 | +To check values: |
| 135 | +``` |
| 136 | +aws --profile "lfproduct-prod" dynamodb scan --table-name "cla-prod-github-orgs" --filter-expression "contains(organization_name,:v)" --expression-attribute-values "{\":v\":{\"S\":\"open-telemetry\"}}" --max-items 100 | jq -r '.Items' |
| 137 | +aws --profile "lfproduct-prod" dynamodb scan --table-name "cla-prod-github-orgs" --filter-expression "contains(organization_name,:v)" --expression-attribute-values "{\":v\":{\"S\":\"openfga\"}}" --max-items 100 | jq -r '.Items' |
| 138 | +aws --profile "lfproduct-prod" dynamodb scan --table-name "cla-prod-github-orgs" --filter-expression "contains(organization_name,:v)" --expression-attribute-values "{\":v\":{\"S\":\"open-telemetry\"}}" --max-items 100 | jq -r '.Items[0].enable_co_authors.M["otel-arrow"]["BOOL"]' |
| 139 | +aws --profile "lfproduct-prod" dynamodb scan --table-name "cla-prod-github-orgs" --filter-expression "contains(organization_name,:v)" --expression-attribute-values "{\":v\":{\"S\":\"openfga\"}}" --max-items 100 | jq -r '.Items[0].enable_co_authors.M["vscode-ext"]["BOOL"]' |
| 140 | +``` |
| 141 | + |
| 142 | +Typical adding a new entry for an organization: |
| 143 | +``` |
| 144 | +STAGE=prod MODE=add-key DEBUG=1 ./utils/enable_co_authors_entry.sh 'open-telemetry' 'opentelemetry-rust' t |
| 145 | +``` |
| 146 | + |
| 147 | + |
| 148 | +# How co-authors are processed |
| 149 | + |
| 150 | +When a commit is made to a repository that has co-authors support enabled, the backend will check if the commit message contains `co-authored-by:` lines/commit trailers (case insensitive). |
| 151 | + |
| 152 | +If it does, the backend will process the co-authors as follows, assume trailer value is `name <email>` like `Lukasz Gryglicki <[email protected]>`: |
| 153 | + |
| 154 | +- First we check if email is in format `[email protected]`. If it is we use number part as GitHub user ID and fetch the user from GitHub API. If the user is found, we use that user as co-author. |
| 155 | + |
| 156 | +- Second we check if email is in format `[email protected]`. If it is we use username part as GitHub username/login and fetch the user from GitHub API. If the user is found, we use that user as co-author. |
| 157 | + |
| 158 | +- Thirs we lookup for email using GitHub API. If the user is found, we use that user as co-author. |
| 159 | + |
| 160 | +- Finally we use the name part for `name <email>` and lookup using GitHub API assuming that this name is GitHub username/login (this is the case for some bots). If the user is found, we use that user as co-author. |
| 161 | + |
| 162 | +We use internal caching while doing all those lookups with cache key `name` and `email` and TTL 24 hours. We even cache by `(name, email)` when nothing is found because this is the most time consuming option. It will have a chance to be found in the future (up to 24 hours from lookup). |
0 commit comments