Skip to content

Commit af4dce7

Browse files
committed
add remove entry workflow
1 parent 03cecb4 commit af4dce7

2 files changed

Lines changed: 75 additions & 0 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Remove Metadata Entry
2+
3+
on:
4+
issues:
5+
types: [labeled]
6+
7+
jobs:
8+
remove_entry:
9+
if: contains(github.event.label.name, 'remove entry')
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v4
14+
15+
- name: Set up Python
16+
uses: actions/setup-python@v5
17+
with:
18+
python-version: "3.9"
19+
20+
- name: Remove entry and update sitemap
21+
env:
22+
ISSUE_TITLE: ${{ github.event.issue.title }}
23+
run: |
24+
python remove_entry.py "$ISSUE_TITLE"
25+
26+
- name: Commit and Push Changes
27+
run: |
28+
git config --global user.name "GitHub Actions"
29+
git config --global user.email "github-actions@github.com"
30+
git add .
31+
git commit -m "Removed entry and updated sitemap for ${{ github.event.issue.title }}"
32+
git push

remove_entry.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Code to remove entries
2+
import os
3+
import sys
4+
import shutil
5+
import subprocess
6+
import re
7+
8+
JSON_FOLDER = 'jsonFiles'
9+
REMOVED_FOLDER = 'removedEntries'
10+
11+
# Find issues with label "remove entry"
12+
def get_folder_name_from_title(issue_title):
13+
if ':' in issue_title: # Get entry name after the colon from the issue title
14+
folder_base = issue_title.split(':', 1)[1].strip()
15+
else:
16+
folder_base = issue_title.strip()
17+
# Sanitize to match folder naming convention
18+
folder_name = re.sub(r'[^A-Za-z0-9_\-]', '_', folder_base)
19+
return folder_name
20+
21+
if __name__ == "__main__":
22+
if len(sys.argv) < 2:
23+
print("Usage: remove_entry.py <issue_title>")
24+
sys.exit(1)
25+
26+
issue_title = sys.argv[1]
27+
# Use the title of the issue to find the associated folder in JsonFiles
28+
folder_name = get_folder_name_from_title(issue_title)
29+
src_path = os.path.join(JSON_FOLDER, folder_name)
30+
dst_path = os.path.join(REMOVED_FOLDER, folder_name)
31+
32+
if not os.path.exists(src_path):
33+
print(f"Folder {src_path} does not exist.")
34+
sys.exit(1)
35+
36+
os.makedirs(REMOVED_FOLDER, exist_ok=True)
37+
# Move that folder into folder "removedEntries"
38+
shutil.move(src_path, dst_path)
39+
print(f"Moved {src_path} to {dst_path}")
40+
41+
# Update the BioEco CSV list and sitemap
42+
subprocess.run([sys.executable, "collectNamesTo_csv.py"], check=True)
43+
subprocess.run([sys.executable, "generate_sitemap.py"], check=True)

0 commit comments

Comments
 (0)