Skip to content

Commit

Permalink
Support mode table and list (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
tungbq authored May 25, 2024
1 parent 59b4133 commit c82930d
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 7 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/generate_content.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
name: Update Content
env:
# Current supported mode: 'table' and 'list'
content_mode: "table"

on:
## Trigger on merge event to main brnach
Expand All @@ -25,7 +28,8 @@ jobs:
- name: Generate content
run: |
echo "Repo owner: ${{ github.repository_owner }}"
./generate_content.sh repository_list.txt ${{ github.repository_owner }}
echo "Content mode: ${{ env.content_mode }}"
./generate_content.sh repository_list.txt ${{ env.content_mode }} ${{ github.repository_owner }}
- name: Create Pull Request
id: cpr
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ If you want to create your own repository landscape similar to this, please foll
- Description: 🐳 Local containerized environment supports various languages.
- <a href="https://github.com/tungbq/LocalEnv/stargazers"><img alt="GitHub Repo stars" src="https://img.shields.io/github/stars/tungbq/LocalEnv"/></a>

For full list of repositories, click [**here**](https://github.com/tungbq?tab=repositories&q=&type=&language=&sort=stargazers).
For full list of repositories, click [**here**](https://github.com/tungbq?tab=repositories&q=&type=&language=&sort=stargazers).
53 changes: 48 additions & 5 deletions generate_content.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#!/bin/bash

REPOSITORY_LIST=$1
MODE=${2:-table}

# User input, or will be automated detected via CI
GITHUB_OWNER=$2
GITHUB_OWNER=$3

if [ -z $REPOSITORY_LIST || ]; then
if [[ -z $REPOSITORY_LIST || -z $MODE || -z $GITHUB_OWNER ]]; then
echo "ERROR: epository list is empty!"
echo "Usage: $0 <repository_list_path> <github_owner>"
echo "Usage: $0 <repository_list_path> <mode> <github_owner>"
exit 1
fi

Expand All @@ -29,6 +30,37 @@ generate_repo_list() {
echo "- $stars" >>README.md
}

# Function to generate table rows
generate_repo_table() {
local index="$1"
local repo_name="$2"
local description="$3"

# Only get base repo name, execlude the username
repo_base_name=$(basename $repo_name)

local repo_hyperlink="<a href=\"https://github.com/$repo_name\">$repo_name</a>"
local stars="<a href=\"https://github.com/$repo_name/stargazers\"><img alt=\"GitHub Repo stars\" src=\"https://img.shields.io/github/stars/$repo_name?style=social\"/></a>"

# At header in the first run
if [[ "$index" == "1" ]]; then
# Start HTML table
echo "<table>" >>README.md
echo " <tr>" >>README.md
echo " <th>Repo URL</th>" >>README.md
echo " <th>Stars</th>" >>README.md
echo " <th>Description</th>" >>README.md
echo " </tr>" >>README.md
fi

echo " <tr>" >>README.md
echo " <th>$repo_hyperlink</th>" >>README.md
echo " <th>$stars</th>" >>README.md
echo " <th>$description</th>" >>README.md
echo " </tr>" >>README.md

}

# Start README file with header
echo "<h1 align=\"center\">Repositories Landscape 💎</h1>" >README.md
echo "<p align=\"center\">Welcome to my repositories landscape 👋</p>" >>README.md
Expand All @@ -51,12 +83,23 @@ while IFS= read -r repo_name; do
# Extract the description from the response using jq (ensure jq is installed)
description=$(echo "$response" | jq -r '.description')

# Generate table row with incremental index
generate_repo_list "$index" "$repo_name" "$description"
if [[ "$MODE" == "table" ]]; then
# Generate table row with incremental index
generate_repo_table "$index" "$repo_name" "$description"
else
# Generate list with incremental index
generate_repo_list "$index" "$repo_name" "$description"
fi

# Increment index
((index++))
done <"$REPOSITORY_LIST"

## Table closing
if [[ "$MODE" == "table" ]]; then
# End HTML table
echo "</table>" >>README.md
fi

echo "" >>README.md
echo "For full list of repositories, click [**here**](https://github.com/${GITHUB_OWNER}?tab=repositories&q=&type=&language=&sort=stargazers)." >>README.md

0 comments on commit c82930d

Please sign in to comment.