Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:

steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit

Expand All @@ -52,7 +52,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4.39.1
uses: github/codeql-action/init@33d7b85da1a04171e211befe2c739303b9a4c066 # v4.39.3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -67,6 +67,6 @@ jobs:
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4.39.1
uses: github/codeql-action/analyze@33d7b85da1a04171e211befe2c739303b9a4c066 # v4.39.3
with:
category: "/language:${{matrix.language}}"
2 changes: 1 addition & 1 deletion .github/workflows/contributors_report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:

steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/copilot-setup-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
# If you do not check out your code, Copilot will do this for you.
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/mark-ready-when-ready.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
github.event.pull_request.draft == true
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
python-version: [3.11, 3.12, 3.13, 3.14]
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:

steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit

Expand All @@ -49,6 +49,6 @@ jobs:
path: results.sarif
retention-days: 5
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@9b3254085494b55a0f7c4c2b3d2d52cc712ce370
uses: github/codeql-action/upload-sarif@33d7b85da1a04171e211befe2c739303b9a4c066
with:
sarif_file: results.sarif
2 changes: 1 addition & 1 deletion .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
pull-requests: read
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/super-linter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
statuses: write
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit

Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#checkov:skip=CKV_DOCKER_2
#checkov:skip=CKV_DOCKER_3
#trivy:ignore:AVD-DS-0002
FROM python:3.15.0-slim@sha256:f5b92f2a669a4c347044f29367f31983280b648250ca94dea66f98c53bc87e58 AS builder
FROM python:3.15.2-slim@sha256:65a65fc7b30b06cb6df4930fd4650697cb23f4c2698ab81fc87e4b031bc36928 AS builder

WORKDIR /action/workspace
COPY pyproject.toml uv.lock *.py /action/workspace/
COPY --from=ghcr.io/astral-sh/uv:0.10.9@sha256:10902f58a1606787602f303954cea099626a4adb02acbac4c69920fe9d278f82 /uv /uvx /bin/

RUN apt-get -y update \
&& apt-get -y install --no-install-recommends gcc=4:14.2.0-1 libc6-dev=2.41-12+deb13u4 libffi-dev=3.4.8-2 \
&& apt-get -y install --no-install-recommends gcc=4:14.2.0-1 libc6-dev=2.41-12+deb13u5 libffi-dev=3.4.8-2 \
&& uv sync --frozen --no-dev --no-editable \
&& rm -rf /var/lib/apt/lists/*

FROM python:3.15.0-slim@sha256:f5b92f2a669a4c347044f29367f31983280b648250ca94dea66f98c53bc87e58
FROM python:3.15.2-slim@sha256:65a65fc7b30b06cb6df4930fd4650697cb23f4c2698ab81fc87e4b031bc36928
LABEL com.github.actions.name="contributors" \
com.github.actions.description="GitHub Action that given an organization or repository, produces information about the contributors over the specified time period." \
com.github.actions.icon="users" \
Expand Down
32 changes: 19 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,25 @@ This action can be configured to authenticate with GitHub App Installation or Pe

#### Other Configuration Options

| field | required | default | description |
| ------------------- | ----------------------------------------------- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `GH_ENTERPRISE_URL` | False | "" | The `GH_ENTERPRISE_URL` is used to connect to an enterprise server instance of GitHub. github.com users should not enter anything here. |
| `ORGANIZATION` | Required to have `ORGANIZATION` or `REPOSITORY` | | The name of the GitHub organization which you want the contributor information of all repos from. ie. github.com/github would be `github` |
| `REPOSITORY` | Required to have `ORGANIZATION` or `REPOSITORY` | | The name of the repository and organization which you want the contributor information from. ie. `github/contributors` or a comma separated list of multiple repositories `github/contributor,super-linter/super-linter` |
| `START_DATE` | False | Beginning of time | The date from which you want to start gathering contributor information. ie. Aug 1st, 2023 would be `2023-08-01`. |
| `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" |
| `OUTPUT_FILENAME` | False | contributors.md | The output filename for the markdown report. ie. OUTPUT_FILENAME = "my-report.md" |
| `SHOW_AVATAR` | False | False | If you want to show profile images in the markdown output. ie. SHOW_AVATAR = "True" or SHOW_AVATAR = "False" |

**Note**: If `start_date` and `end_date` are specified then the action will determine if the contributor is new. A new contributor is one that has contributed in the date range specified but not before the start date.
| field | required | default | description |
| ------------------- | ----------------------------------------------- | ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `GH_ENTERPRISE_URL` | False | "" | The `GH_ENTERPRISE_URL` is used to connect to an enterprise server instance of GitHub. github.com users should not enter anything here. |
| `ORGANIZATION` | Required to have `ORGANIZATION` or `REPOSITORY` | | The name of the GitHub organization which you want the contributor information of all repos from. ie. github.com/github would be `github` |
| `REPOSITORY` | Required to have `ORGANIZATION` or `REPOSITORY` | | The name of the repository and organization which you want the contributor information from. ie. `github/contributors` or a comma separated list of multiple repositories `github/contributor,super-linter/super-linter` |
| `START_DATE` | False | Beginning of time | The date from which you want to start gathering contributor information. ie. Aug 1st, 2023 would be `2023-08-01`. |
| `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" |
| `OUTPUT_FILENAME` | False | contributors.md | The output filename for the markdown report. ie. OUTPUT_FILENAME = "my-report.md" |
| `SHOW_AVATAR` | False | False | If you want to show profile images in the markdown output. ie. SHOW_AVATAR = "True" or SHOW_AVATAR = "False" |
| `SORT_COLUMN` | False | contribution_count | The column you want to sort the table with. Possible values: `username` (column of strings), `contribution_count` (column of integers) or `new_contributor` (column of booleans, whether the given username is a new contributor) |
| `SORT_ORDER` | False | desc | The order the SORT_COLUMN column will be sorted. Possibles values: `asc` for ascending order or `desc` for descending order. |
| `SKIP_SUMMARY` | False | False | If you want to hide the summary with total contributions statistics above the contributors table. ie. SKIP_SUMMARY = "True" or SKIP_SUMMARY = "False" |

**Notes**:
Comment thread
oleole39 marked this conversation as resolved.
Resolved

- If `start_date` and `end_date` are specified then the action will determine if the contributor is new. A new contributor is one that has contributed in the date range specified but not before the start date.
- If `sort_column` and `sort_order` are defined with invalid values, the action will run using the default values as fallback.

**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
16 changes: 12 additions & 4 deletions contributors.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# pylint: disable=broad-exception-caught
"""This file contains the main() and other functions needed to get contributor information from the organization or repository"""

from datetime import datetime, timezone
from datetime import UTC, datetime

import auth
import contributor_stats
Expand Down Expand Up @@ -29,6 +29,9 @@ def main():
link_to_profile,
output_filename,
show_avatar,
sort_column,
sort_order,
skip_summary,
) = env.get_env_vars()

# Auth to GitHub.com
Expand Down Expand Up @@ -85,7 +88,10 @@ def main():
sponsor_info,
link_to_profile,
ghe,
show_avatar,
show_avatar=show_avatar,
sort_column=sort_column,
sort_order=sort_order,
skip_summary=skip_summary,
)
json_writer.write_to_json(
filename="contributors.json",
Expand All @@ -96,6 +102,8 @@ def main():
sponsor_info=sponsor_info,
link_to_profile=link_to_profile,
contributors=contributors,
sort_column=sort_column,
sort_order=sort_order,
)


Expand Down Expand Up @@ -165,8 +173,8 @@ def get_contributors(repo: object, start_date: str, end_date: str, ghe: str):
avatars: dict[str, str] = {}
counts: dict[str, int] = {}
for commit in repo.get_commits(
since=datetime.fromisoformat(start_date).replace(tzinfo=timezone.utc),
until=datetime.fromisoformat(end_date).replace(tzinfo=timezone.utc),
since=datetime.fromisoformat(start_date).replace(tzinfo=UTC),
until=datetime.fromisoformat(end_date).replace(tzinfo=UTC),
):
login = getattr(commit.author, "login", None)
if not login or "[bot]" in login:
Expand Down
36 changes: 33 additions & 3 deletions env.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def validate_date_format(env_var_name: str) -> str:
pattern = "%Y-%m-%d"
try:
datetime.datetime.strptime(date_to_validate, pattern).replace(
tzinfo=datetime.timezone.utc
tzinfo=datetime.UTC
)
except ValueError as exc:
raise ValueError(
Expand Down Expand Up @@ -92,12 +92,12 @@ def validate_date_range(start_date: str, end_date: str) -> None:
try:
start = (
datetime.datetime.strptime(start_date, pattern)
.replace(tzinfo=datetime.timezone.utc)
.replace(tzinfo=datetime.UTC)
.date()
)
end = (
datetime.datetime.strptime(end_date, pattern)
.replace(tzinfo=datetime.timezone.utc)
.replace(tzinfo=datetime.UTC)
.date()
)
except ValueError as exc:
Expand Down Expand Up @@ -132,6 +132,19 @@ def validate_output_filename(output_filename: str) -> str:
return filename


def validate_allowed_values(
env_var_name: str, allowed_values: list[str], default: str
) -> str:
"""Check that env variable is contained in a list of defined values or set a default one.
Returns a lowercase value.
"""
allowed_values = [val.strip().lower() for val in allowed_values]
var_to_validate = os.getenv(env_var_name, default).strip().lower()
if var_to_validate in allowed_values:
return var_to_validate
return default.strip().lower()
Comment thread
oleole39 marked this conversation as resolved.
Resolved


def get_env_vars(
test: bool = False,
) -> tuple[
Expand All @@ -149,6 +162,9 @@ def get_env_vars(
bool,
str,
bool,
str,
str,
bool,
]:
"""
Get the environment variables for use in the action.
Expand All @@ -169,6 +185,9 @@ def get_env_vars(
end_date (str): The end date to get contributor information to
sponsor_info (str): Whether to get sponsor information on the contributor
link_to_profile (str): Whether to link username to Github profile in markdown output
sort_column (str): The column the table should be sorted by ('username', 'contribution_count' or 'new_contributor'). Case insensitive.
sort_order (str): The sorting order ('asc' or 'desc'). Case insensitive.
skip_summary (str): Whether to print the summary before the table
"""

if not test:
Expand Down Expand Up @@ -222,6 +241,14 @@ def get_env_vars(
repository.strip() for repository in repositories_str.split(",")
]

sort_column = validate_allowed_values(
"SORT_COLUMN",
["username", "contribution_count", "new_contributor"],
"contribution_count",
)
sort_order = validate_allowed_values("SORT_ORDER", ["asc", "desc"], "desc")
skip_summary = get_bool_env_var("SKIP_SUMMARY", False)

return (
organization,
repositories_list,
Expand All @@ -237,4 +264,7 @@ def get_env_vars(
link_to_profile,
output_filename,
show_avatar,
sort_column,
sort_order,
skip_summary,
)
Loading