@@ -33,10 +33,19 @@ jobs:
3333 )
3434 ]
3535 | .[0:10]
36- | .[]
37- | "| [\(.name)](\(.html_url)) | \(.description // "A Chef cookbook") | \(.updated_at | split("T")[0]) |"
38- ' > /tmp/cookbooks.txt
39- echo "Fetched $(wc -l < /tmp/cookbooks.txt) cookbooks"
36+ ' > /tmp/repos.json
37+ echo "Fetched $(jq 'length' /tmp/repos.json) cookbooks"
38+
39+ - name : Fetch latest merged PRs
40+ env :
41+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
42+ run : |
43+ mkdir -p /tmp/prs
44+ for repo in $(jq -r '.[].name' /tmp/repos.json); do
45+ gh api "repos/sous-chefs/${repo}/pulls?state=closed&sort=updated&direction=desc&per_page=5" \
46+ --jq '[.[] | select(.merged_at != null)][0]' \
47+ > "/tmp/prs/${repo}.json" 2>/dev/null || echo 'null' > "/tmp/prs/${repo}.json"
48+ done
4049
4150 - name : Fetch org members
4251 env :
@@ -52,12 +61,39 @@ jobs:
5261 - name : Update README
5362 run : |
5463 ruby - <<'RUBYEOF'
64+ require "json"
65+ require "time"
66+
5567 readme = "profile/README.md"
5668 content = File.read(readme)
5769
58- rows = File.read("/tmp/cookbooks.txt").strip
70+ repos = JSON.parse(File.read("/tmp/repos.json"))
71+
72+ rows = repos.map do |repo|
73+ name = repo["name"]
74+ url = repo["html_url"]
75+ desc = repo["description"] || "A Chef cookbook"
76+ updated = Time.parse(repo["updated_at"]).strftime("%b %d, %Y")
77+
78+ pr_path = "/tmp/prs/#{name}.json"
79+ pr = begin
80+ data = JSON.parse(File.read(pr_path))
81+ data unless data.nil? || data.is_a?(String)
82+ rescue JSON::ParserError, Errno::ENOENT
83+ nil
84+ end
85+
86+ change = if pr
87+ "[#{pr['title']}](#{pr['html_url']})"
88+ else
89+ "—"
90+ end
91+
92+ "| [#{name}](#{url}) | #{desc} | #{change} | #{updated} |"
93+ end
94+
5995 unless rows.empty?
60- table = "| Cookbook | Description | Last Updated |\n| --- | --- | --- |\n#{rows}"
96+ table = "| Cookbook | Description | Latest Change | Last Updated |\n| --- | --- | --- | --- | \n#{rows.join("\n") }"
6197 content.gsub!(/<!-- COOKBOOKS_START -->.*?<!-- COOKBOOKS_END -->/m,
6298 "<!-- COOKBOOKS_START -->\n#{table}\n<!-- COOKBOOKS_END -->")
6399 end
0 commit comments