Auto fetch cards for certain projects

オープン
#193 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
68/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
git, github-actions, python
領域
build-system

調査の方向性

Start with the proposed scripts/sync_folders.py and JSON configuration, then inspect the repository’s existing GitHub Actions workflow and rendering setup. Confirm the two source folders and destination paths match the project structure, and check whether cards depend on assets outside those folders. Done means CI syncs the configured folders before rendering and the generated destination is ignored by Git.

索引モデルが issue の本文から書いたものです。

説明

Suggested setup

Put the fetch in a script so CI and local use are identical:

[
  {
    "path_to_folder_to_synchronize_from": "https://github.com/InseeFrLab/codif-ape-prez/tree/main/cards",
    "path_to_folder_to_synchronize_to": "project/2022_codif_ape/cards"
  },
  {
    "path_to_folder_to_synchronize_from": "https://github.com/InseeFrLab/satellite-images-docs/tree/main/cards",
    "path_to_folder_to_synchronize_to": "project/2022_satellites/cards"
  }
]
#scripts/sync_folders.py
"""Sync folders from other GitHub repos into this repo, based on a JSON list."""
import json
import re
import shutil
import subprocess
import sys
import tempfile
from pathlib import Path

CONFIG = Path(sys.argv[1] if len(sys.argv) > 1 else "scripts/sync_folders.json")

# https://github.com/<owner>/<repo>/tree/<branch>/<folder>
URL_RE = re.compile(
    r"^https://github\.com/(?P<owner>[^/]+)/(?P<repo>[^/]+)"
    r"/tree/(?P<ref>[^/]+)/(?P<folder>.+?)/?$"
)


def run(*args):
    subprocess.run(args, check=True)


def sync(src_url: str, dest: str) -> None:
    m = URL_RE.match(src_url)
    if not m:
        raise ValueError(f"Unsupported URL (expected .../tree/<branch>/<folder>): {src_url}")
    repo_url = f"https://github.com/{m['owner']}/{m['repo']}.git"
    ref, folder = m["ref"], m["folder"]

    with tempfile.TemporaryDirectory() as tmp:
        run("git", "clone", "--depth", "1", "--filter=blob:none", "--sparse",
            "--branch", ref, repo_url, tmp)
        run("git", "-C", tmp, "sparse-checkout", "set", folder)

        source = Path(tmp) / folder
        if not source.is_dir():
            raise FileNotFoundError(f"{folder} not found in {repo_url}@{ref}")

        dest_path = Path(dest)
        if dest_path.exists():
            shutil.rmtree(dest_path)
        dest_path.parent.mkdir(parents=True, exist_ok=True)
        shutil.copytree(source, dest_path)
        print(f"Synced {src_url} -> {dest}")


def main() -> None:
    for entry in json.loads(CONFIG.read_text()):
        sync(
            entry["path_to_folder_to_synchronize_from"],
            entry["path_to_folder_to_synchronize_to"],
        )


if __name__ == "__main__":
    main()

In the workflow, run it before rendering:

- uses: actions/checkout@v4
- name: Sync external folders
  run: uv run python scripts/sync_folders.py
- name: Render
  run: uv run quarto render

Add project/2022_codif_ape/cards/ to .gitignore so the copied files never get committed. If the repo is public, no token is needed.

If the cards reference images or other assets stored outside cards/ in the upstream repo, copy those folders too (add them to sparse-checkout set), otherwise the listing thumbnails may break.

主要言語
CSS
スター
14
フォーク
13
平均マージ
1日 9時間
マージ済み PR(30日)
4

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

InseeFrLab/ssphub のほかの issue

InseeFrLab/ssphub の issue をすべて見る

似ている issue

Build System の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。