From db957aac7c02716e83c9d86a998c2600c68c235a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 26 Oct 2025 08:44:09 +0000 Subject: [PATCH 1/5] Initial plan From 30c22a3f6f98ce5e1fc2cbc927f758e3b1e09a48 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 26 Oct 2025 08:47:34 +0000 Subject: [PATCH 2/5] Update populate_contributors.py to use urllib.request instead of urllib2 Co-authored-by: RitikaPahwa4444 <83745993+RitikaPahwa4444@users.noreply.github.com> --- populate_contributors.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/populate_contributors.py b/populate_contributors.py index a8e880f..0458a41 100644 --- a/populate_contributors.py +++ b/populate_contributors.py @@ -1,8 +1,9 @@ import json -import urllib2 +import urllib.request GITHUB_GET_CONTRIBUTORS_API = "https://api.github.com/repos/commons-app/apps-android-commons/contributors" -response = urllib2.urlopen(GITHUB_GET_CONTRIBUTORS_API).read() +req = urllib.request.Request(GITHUB_GET_CONTRIBUTORS_API, headers={'User-Agent': 'Mozilla/5.0'}) +response = urllib.request.urlopen(req).read() response_json = json.loads(response) # Replace the API call above with the two lines below if your Python is blocked from using the Internet. From 96367d32ab0c939222c440da69ed2934ec643db8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 26 Oct 2025 08:49:26 +0000 Subject: [PATCH 3/5] Add GitHub workflow to update contributors monthly Co-authored-by: RitikaPahwa4444 <83745993+RitikaPahwa4444@users.noreply.github.com> --- .github/workflows/update-contributors.yml | 89 +++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 .github/workflows/update-contributors.yml diff --git a/.github/workflows/update-contributors.yml b/.github/workflows/update-contributors.yml new file mode 100644 index 0000000..a4dd7e2 --- /dev/null +++ b/.github/workflows/update-contributors.yml @@ -0,0 +1,89 @@ +name: Update Contributors + +on: + schedule: + # Run on the 1st of every month at 00:00 UTC + - cron: '0 0 1 * *' + workflow_dispatch: # Allow manual triggering + +jobs: + update-contributors: + runs-on: ubuntu-latest + + steps: + - name: Checkout maintenance repo + uses: actions/checkout@v4 + with: + path: maintenance + + - name: Checkout apps-android-commons repo + uses: actions/checkout@v4 + with: + repository: commons-app/apps-android-commons + token: ${{ secrets.PAT_TOKEN }} + path: apps-android-commons + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.x' + + - name: Generate contributors table + id: generate + run: | + cd maintenance + python populate_contributors.py > /tmp/contributors_table.txt + echo "Generated contributors table" + cat /tmp/contributors_table.txt + + - name: Update README with new contributors + run: | + cd apps-android-commons + + # Read the current README + README_FILE="README.md" + + # Create a Python script to update the README + cat > /tmp/update_readme.py << 'PYTHON_SCRIPT' + import re + import sys + + # Read the contributors table + with open('/tmp/contributors_table.txt', 'r') as f: + new_table = f.read().strip() + + # Read the README + with open('README.md', 'r') as f: + readme_content = f.read() + + # Find the Contributors section and replace it + # Pattern: Find everything between "## Contributors ##" and ".. and [many more]" + pattern = r'(## Contributors ##\s+Thank you all for your work!\s+)(.*?)(\s+\.\. and \[many more\])' + + replacement = r'\1' + new_table + r'\3' + + updated_content = re.sub(pattern, replacement, readme_content, flags=re.DOTALL) + + # Write the updated README + with open('README.md', 'w') as f: + f.write(updated_content) + + print("README updated successfully") + PYTHON_SCRIPT + + python /tmp/update_readme.py + + - name: Commit and push changes + run: | + cd apps-android-commons + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + + if git diff --quiet; then + echo "No changes to commit" + else + git add README.md + git commit -m "Update contributors list" + git push + echo "Changes pushed successfully" + fi From af647ca04266e756e7393dd38f81ba190a234618 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 26 Oct 2025 08:51:33 +0000 Subject: [PATCH 4/5] Improve workflow by extracting Python script and adding error handling Co-authored-by: RitikaPahwa4444 <83745993+RitikaPahwa4444@users.noreply.github.com> --- .github/workflows/update-contributors.yml | 37 +----------- update_readme.py | 68 +++++++++++++++++++++++ 2 files changed, 71 insertions(+), 34 deletions(-) create mode 100644 update_readme.py diff --git a/.github/workflows/update-contributors.yml b/.github/workflows/update-contributors.yml index a4dd7e2..50e4bdf 100644 --- a/.github/workflows/update-contributors.yml +++ b/.github/workflows/update-contributors.yml @@ -31,6 +31,7 @@ jobs: - name: Generate contributors table id: generate run: | + set -e cd maintenance python populate_contributors.py > /tmp/contributors_table.txt echo "Generated contributors table" @@ -38,40 +39,8 @@ jobs: - name: Update README with new contributors run: | - cd apps-android-commons - - # Read the current README - README_FILE="README.md" - - # Create a Python script to update the README - cat > /tmp/update_readme.py << 'PYTHON_SCRIPT' - import re - import sys - - # Read the contributors table - with open('/tmp/contributors_table.txt', 'r') as f: - new_table = f.read().strip() - - # Read the README - with open('README.md', 'r') as f: - readme_content = f.read() - - # Find the Contributors section and replace it - # Pattern: Find everything between "## Contributors ##" and ".. and [many more]" - pattern = r'(## Contributors ##\s+Thank you all for your work!\s+)(.*?)(\s+\.\. and \[many more\])' - - replacement = r'\1' + new_table + r'\3' - - updated_content = re.sub(pattern, replacement, readme_content, flags=re.DOTALL) - - # Write the updated README - with open('README.md', 'w') as f: - f.write(updated_content) - - print("README updated successfully") - PYTHON_SCRIPT - - python /tmp/update_readme.py + set -e + python maintenance/update_readme.py /tmp/contributors_table.txt apps-android-commons/README.md - name: Commit and push changes run: | diff --git a/update_readme.py b/update_readme.py new file mode 100644 index 0000000..3cce63e --- /dev/null +++ b/update_readme.py @@ -0,0 +1,68 @@ +import re +import sys + +def update_readme_with_contributors(contributors_table_path, readme_path): + """ + Update the README file with the new contributors table. + + Args: + contributors_table_path: Path to the file containing the new contributors table + readme_path: Path to the README file to update + + Returns: + bool: True if the README was updated, False otherwise + """ + # Read the contributors table + try: + with open(contributors_table_path, 'r') as f: + new_table = f.read().strip() + except FileNotFoundError: + print(f"Error: Contributors table file not found: {contributors_table_path}", file=sys.stderr) + sys.exit(1) + + # Read the README + try: + with open(readme_path, 'r') as f: + readme_content = f.read() + except FileNotFoundError: + print(f"Error: README file not found: {readme_path}", file=sys.stderr) + sys.exit(1) + + # Find the Contributors section and replace it + # Pattern: Find everything between "## Contributors ##" and ".. and [many more]" + pattern = r'(## Contributors ##\s+Thank you all for your work!\s+)(.*?)(\s+\.\. and \[many more\])' + + # Check if the pattern matches + if not re.search(pattern, readme_content, flags=re.DOTALL): + print("Error: Could not find Contributors section in README. The README format may have changed.", file=sys.stderr) + print("Expected to find: '## Contributors ##' followed by 'Thank you all for your work!' and '.. and [many more]'", file=sys.stderr) + sys.exit(1) + + replacement = r'\1' + new_table + r'\3' + updated_content = re.sub(pattern, replacement, readme_content, flags=re.DOTALL) + + # Verify the replacement was successful + if updated_content == readme_content: + print("Warning: No changes were made to the README. The contributors table may be identical.", file=sys.stderr) + return False + + # Write the updated README + try: + with open(readme_path, 'w') as f: + f.write(updated_content) + except Exception as e: + print(f"Error: Failed to write updated README: {e}", file=sys.stderr) + sys.exit(1) + + print("README updated successfully") + return True + +if __name__ == "__main__": + if len(sys.argv) != 3: + print(f"Usage: {sys.argv[0]} ", file=sys.stderr) + sys.exit(1) + + contributors_table_path = sys.argv[1] + readme_path = sys.argv[2] + + update_readme_with_contributors(contributors_table_path, readme_path) From fb70a15e3ae7fb9032ce691f5d6dced8d0763e75 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 26 Oct 2025 08:54:47 +0000 Subject: [PATCH 5/5] Add explicit permissions to workflow for security Co-authored-by: RitikaPahwa4444 <83745993+RitikaPahwa4444@users.noreply.github.com> --- .github/workflows/update-contributors.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/update-contributors.yml b/.github/workflows/update-contributors.yml index 50e4bdf..d15989b 100644 --- a/.github/workflows/update-contributors.yml +++ b/.github/workflows/update-contributors.yml @@ -9,6 +9,8 @@ on: jobs: update-contributors: runs-on: ubuntu-latest + permissions: + contents: write # Required to push changes to the repository steps: - name: Checkout maintenance repo