Skip to content

Commit

Permalink
Match upstream naming of organisation (organization)
Browse files Browse the repository at this point in the history
  • Loading branch information
HCookie committed Oct 16, 2024
1 parent b81302c commit 310113c
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 39 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/contributors_report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ jobs:
echo "END_DATE=$end_date" >> "$GITHUB_ENV"
- name: Run contributor action
uses: hcookie/organisational_contributors@1286dc8d6904a9a7f735e28b7503be164fb7d4b9
uses: hcookie/organizational_contributors@1286dc8d6904a9a7f735e28b7503be164fb7d4b9
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
START_DATE: ${{ env.START_DATE }}
END_DATE: ${{ env.END_DATE }}
REPOSITORY: hcookie/organisational_contributors
REPOSITORY: hcookie/organizational_contributors
# SPONSOR_INFO: "true"

- name: Show Contributor
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/contributors_report_testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ jobs:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# START_DATE: ${{ env.START_DATE }}
# END_DATE: ${{ env.END_DATE }}
REPOSITORY: hcookie/organisational_contributors
SHOW_ORGANISATIONS: [ecmwf]
REPOSITORY: hcookie/organizational_contributors
SHOW_ORGANIZATIONS: [ecmwf]
# SPONSOR_INFO: "true"

- name: Show Contributor
Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Contributors sorted by Organisation action
# Contributors sorted by Organization action

[![Python package](https://github.com/hcookie/contributors/actions/workflows/python-ci.yml/badge.svg)](https://github.com/hcookie/contributors/actions/workflows/python-ci.yml)
[![Docker Image CI](https://github.com/hcookie/contributors/actions/workflows/docker-ci.yml/badge.svg)](https://github.com/hcookie/contributors/actions/workflows/docker-ci.yml)
[![CodeQL](https://github.com/hcookie/contributors/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/hcookie/contributors/actions/workflows/github-code-scanning/codeql)[![OpenSSF Scorecard](https://api.scorecard.dev/projects/github.com/github/contributors/badge)](https://scorecard.dev/viewer/?uri=github.com/github/contributors)

This is a GitHub Action that given an organization or specified repositories, produces information about the [contributors](https://chaoss.community/kb/metric-contributors/) sorted by organisation.
This is a GitHub Action that given an organization or specified repositories, produces information about the [contributors](https://chaoss.community/kb/metric-contributors/) sorted by organization.

Similar actions to help you recognize contributors by putting them into a `README` or `CONTRIBUTORS.md` include:

Expand All @@ -13,8 +13,8 @@ Similar actions to help you recognize contributors by putting them into a `READM

## Example use cases

- As a maintainer, you may want to acknowledge contributors from various organisations in a discussion post
- A repository wants to track contributions from organisations
- As a maintainer, you may want to acknowledge contributors from various organizations in a discussion post
- A repository wants to track contributions from organizations

## Support

Expand Down Expand Up @@ -80,7 +80,7 @@ This action can be configured to authenticate with GitHub App Installation or Pe
| `END_DATE` | False | Current Date | The date at which you want to stop gathering contributor information. Must be later than the `START_DATE`. ie. Aug 2nd, 2023 would be `2023-08-02` |
| `SPONSOR_INFO` | False | False | If you want to include sponsor information in the output. This will include the sponsor count and the sponsor URL. This will impact action performance. ie. SPONSOR_INFO = "False" or SPONSOR_INFO = "True" |
| `LINK_TO_PROFILE` | False | True | If you want to link usernames to their GitHub profiles in the output. ie. LINK_TO_PROFILE = "True" or LINK_TO_PROFILE = "False" |
| `SHOW_ORGANISATIONS` | False | [] | Organisations to show in the contributors table. Will be evaluated in order, and a user only added to only the first one they are a part of. Any contributors with no organisation will be shown in independent. Set to 'all' to show all organisations.
| `SHOW_ORGANIZATIONS` | False | [] | Organizations to show in the contributors table. Will be evaluated in order, and a user only added to only the first one they are a part of. Any contributors with no organization will be shown in independent. Set to 'all' to show all organizations.
| `CONTRIB_FILENAME` | False | "contibutors" | Filename to add contributors to. Will create both an 'md', and 'json' file with contents.

**Performance Note:** Using start and end dates will reduce speed of the action by approximately 63X. ie without dates if the action takes 1.7 seconds, it will take 1 minute and 47 seconds.
Expand Down Expand Up @@ -121,13 +121,13 @@ jobs:
echo "END_DATE=$end_date" >> "$GITHUB_ENV"
- name: Run contributor action
uses: hcookie/organisational_contributors@v1
uses: hcookie/organizational_contributors@v1
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
START_DATE: ${{ env.START_DATE }}
END_DATE: ${{ env.END_DATE }}
ORGANIZATION: <YOUR_ORGANIZATION_GOES_HERE>
SHOW_ORGANISATIONS: [ORGANISATIONS_TO_SHOW_HERE]
SHOW_ORGANIZATIONS: [ORGANIZATIONS_TO_SHOW_HERE]
CONTRIB_FILENAME: "contributors"

- name: Show Contributor
Expand All @@ -149,17 +149,17 @@ jobs:
# Contributors
- Date range for contributor list: 2021-01-01 to 2023-10-10
- Organization: ORGANISATION_HERE
- Organization: ORGANIZATION_HERE
| Total Contributors | Total Contributions | % new contributors |
| ------------------ | ------------------- | ------------------ |
| 1 | 143 | 0% |
## ORGANISATION_HERE
## ORGANIZATION_HERE
| Username | All Time Contribution Count | New Contributor | Commits between 2021-01-01 and 2023-10-10 |
| --------- | --------------------------- | --------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| @hcookie | 143 | False | [organisation/repo]() |
| @hcookie | 143 | False | [organization/repo]() |
```

## Local usage without Docker
Expand Down
4 changes: 2 additions & 2 deletions contributors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def main():
environment.repositories_list,
environment.sponsor_info,
environment.link_to_profile,
environment.show_organisations_list,
environment.show_organizations_list,
)
# TODO HCookie Fix to json
json_writer.write_to_json(
Expand Down Expand Up @@ -165,7 +165,7 @@ def get_contributors(
contribution_count=user.contributions_count,
commit_url=commit_url,
sponsor_info="",
organisations=list(map(lambda x: x.url.split("/")[-1], user.organizations())),
organizations=list(map(lambda x: x.url.split("/")[-1], user.organizations())),
)
contributors.append(contributor)
except Exception as e:
Expand Down
2 changes: 1 addition & 1 deletion contributors/contributor_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ContributorStats:
contribution_count: int
commit_url: str
sponsor_info: str
organisations: list[str] = field(default_factory=list)
organizations: list[str] = field(default_factory=list)


def is_new_contributor(username: str, returning_contributors: list) -> bool:
Expand Down
16 changes: 8 additions & 8 deletions contributors/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class EnvironmentConfig:
end_date: str
sponsor_info: bool
link_to_profile: bool
show_organisations_list: list[str]
show_organizations_list: list[str]
filename: str = "contributors"


Expand Down Expand Up @@ -123,8 +123,8 @@ def get_env_vars(
whether to get sponsor information on the contributor
link_to_profile, bool:
whether to link username to Github profile in markdown output
show_organisations_list, list:
Organisations to show in order of preference
show_organizations_list, list:
Organizations to show in order of preference
"""

Expand Down Expand Up @@ -152,7 +152,7 @@ def get_env_vars(
ghe = os.getenv("GH_ENTERPRISE_URL", default="").strip()
filename = os.getenv("CONTRIB_FILENAME", default="contributors").strip()

show_organisations = os.getenv("SHOW_ORGANISATIONS", default="").strip()
show_organizations = os.getenv("SHOW_ORGANIZATIONS", default="").strip()

start_date = validate_date_format("START_DATE")
end_date = validate_date_format("END_DATE")
Expand All @@ -165,9 +165,9 @@ def get_env_vars(
if repositories_str:
repositories_list = [repository.strip() for repository in repositories_str.split(",")]

show_organisations_list = []
if show_organisations:
show_organisations_list = [org.strip() for org in show_organisations.split(",")]
show_organizations_list = []
if show_organizations:
show_organizations_list = [org.strip() for org in show_organizations.split(",")]

return EnvironmentConfig(
organization,
Expand All @@ -181,6 +181,6 @@ def get_env_vars(
end_date,
sponsor_info,
link_to_profile,
show_organisations_list,
show_organizations_list,
filename=filename,
)
20 changes: 10 additions & 10 deletions contributors/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def write_to_markdown(
repository,
sponsor_info,
link_to_profile,
show_organisations_list,
show_organizations_list,
):
"""
This function writes a list of collaborators to a markdown file in table format.
Expand All @@ -32,7 +32,7 @@ def write_to_markdown(
repository (str): The repository for which the contributors are being listed.
sponsor_info (str): True if the user wants the sponsor_url shown in the report
link_to_profile (str): True if the user wants the username linked to Github profile in the report
show_organisations_list (list): Organisations to show
show_organizations_list (list): Organizations to show
Returns:
None
Expand All @@ -47,7 +47,7 @@ def write_to_markdown(
repository,
sponsor_info,
link_to_profile,
show_organisations_list,
show_organizations_list,
)

# Put together the summary table including # of new contributions, # of new contributors, % new contributors, % returning contributors
Expand Down Expand Up @@ -148,7 +148,7 @@ def get_contributor_table(
repository,
sponsor_info,
link_to_profile,
show_organisations_list,
show_organizations_list,
):
"""
This function returns a string containing a markdown table of the contributors and the total contribution count.
Expand Down Expand Up @@ -183,7 +183,7 @@ def get_contributor_table(

total_contributions = 0

organisation_contributors = defaultdict(list)
organization_contributors = defaultdict(list)

for collaborator in collaborators:
total_contributions += collaborator.contribution_count
Expand Down Expand Up @@ -215,16 +215,16 @@ def get_contributor_table(

added_to_org: bool = False

for org in collaborator.organisations or []:
if org in show_organisations_list or "all" in show_organisations_list:
organisation_contributors[org].append(row)
for org in collaborator.organizations or []:
if org in show_organizations_list or "all" in show_organizations_list:
organization_contributors[org].append(row)
added_to_org = True
break

if not added_to_org:
organisation_contributors["Independent"].append(row)
organization_contributors["Independent"].append(row)

tables = {org: headers + "".join(rows) for org, rows in organisation_contributors.items()}
tables = {org: headers + "".join(rows) for org, rows in organization_contributors.items()}

# table += row
return tables, total_contributions
6 changes: 3 additions & 3 deletions tests/test_contributors.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_get_contributors(self, mock_contributor_stats):
contribution_count = 100,
commit_url ='https://github.com/owner/repo/commits?author=user&since=2022-01-01&until=2022-12-31',
sponsor_info='',
organisations=[]
organizations=[]
)

@patch("contributors.get_contributors")
Expand Down Expand Up @@ -71,7 +71,7 @@ def test_get_all_contributors_with_organization(self, mock_get_contributors):
contribution_count=200,
commit_url = "commit_url, commit_url",
sponsor_info = "sponsor_url_1",
organisations= [],
organizations= [],
),
],
)
Expand Down Expand Up @@ -142,7 +142,7 @@ def test_get_contributors_skip_users_with_no_commits(self, mock_contributor_stat
contribution_count=100,
commit_url="https://github.com/owner/repo/commits?author=user&since=2022-01-01&until=2022-12-31",
sponsor_info='',
organisations=[],
organizations=[],
)


Expand Down
2 changes: 1 addition & 1 deletion tests/test_json_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def setUp(self):
"new_contributor": False,
"avatar_url": "https://test_url.com",
"contribution_count": 10,
'organisations': [],
'organizations': [],
"commit_url": "https://test_commit_url.com",
"sponsor_info": "",
}
Expand Down

0 comments on commit 310113c

Please sign in to comment.