-
Notifications
You must be signed in to change notification settings - Fork 5
/
generate_content.sh
executable file
·90 lines (70 loc) · 3.2 KB
/
generate_content.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/bash
REPOSITORY_LIST=$1
MODE=${2:-table}
# User input, or will be automated detected via CI
GITHUB_OWNER=$3
if [[ -z $REPOSITORY_LIST || -z $MODE || -z $GITHUB_OWNER ]]; then
echo "ERROR: epository list is empty!"
echo "Usage: $0 <repository_list_path> <mode> <github_owner>"
exit 1
fi
# Function to generate table rows
generate_repo_list() {
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\" /></a>"
echo "## $index. $repo_base_name" >>README.md
echo "- URL: $repo_hyperlink" >>README.md
echo "- Description: $description" >>README.md
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_base_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=flat\" height=\"20\"/></a>"
# At header in the first run
if [[ "$index" == "1" ]]; then
echo "" >> README.md
echo "| ID | URL | Description | Stars |" >> README.md
echo "| :-- | :--------------- | :--------------------------------------------- | :------ |" >> README.md
fi
echo "| $index | $repo_hyperlink | $description | $stars |" >> 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
echo "" >>README.md
echo "If you want to create your own repository landscape similar to this, please follow this [**guide**](./create-repo-landscape.md) 📖" >>README.md
## Seperator to create following list
echo "" >>README.md
# Start with index 1 for first repo
index=1
while IFS= read -r repo_name; do
echo "Working on repo: $repo_name, with index: $index"
# Make the API request to get repository information
response=$(curl -s "https://api.github.com/repos/$repo_name")
echo "Response:"
echo "$response"
# Extract the description from the response using jq (ensure jq is installed)
description=$(echo "$response" | jq -r '.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"
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