Skip to content

Commit

Permalink
fetching project info from GitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
mackuba committed Nov 20, 2024
1 parent d2519d0 commit a1ac4cc
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 25 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
_data/github_info.yml
_site
.sass-cache
.jekyll-cache
.jekyll-metadata
config/auth.yml
vendor
108 changes: 108 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
require 'json'
require 'net/http'
require 'yaml'

task :update_metadata do
yamls = Dir['_data/projects/*.yml']
urls = yamls.map { |x| YAML.load(File.read(x))['repos'] }.flatten.map { |x| x['url'] }
config = YAML.load(File.read('config/auth.yml'))

data = {}
users = {}
hh = { 'Authorization' => 'Bearer ' + config['github_token'] }

urls.each do |url|
p url
if url =~ %r{^https://github\.com/([\w\-\.]+)/([\w\-\.]+)}
user, repo = $1, $2
response = Net::HTTP.get_response(URI("https://api.github.com/repos/#{user}/#{repo}"), hh)

if response.code.to_i == 200
json = JSON.parse(response.body)

data[url] = {
'name' => json['name'],
'description' => json['description'],
'user_login' => json['owner']['login'],
'homepage' => json['homepage'],
'stars' => json['stargazers_count'],
'license' => json['license'] && json['license']['spdx_id']
}

response = Net::HTTP.get_response(URI("https://api.github.com/repos/#{user}/#{repo}/releases/latest"), hh)

if response.code.to_i == 200
json = JSON.parse(response.body)

data[url]['last_release'] = {
'tag_name' => json['tag_name'],
'name' => json['name'],
'draft' => json['draft'],
'prerelease' => json['prerelease'],
'created_at' => json['created_at'],
'published_at' => json['published_at']
}
elsif response.code.to_i != 404
puts "Invalid response for #{response.uri}: #{response}"
end

response = Net::HTTP.get_response(URI("https://api.github.com/repos/#{user}/#{repo}/tags"), hh)

if response.code.to_i == 200
json = JSON.parse(response.body)[0]

if json
name = json['name']
response = Net::HTTP.get_response(URI(json['commit']['url']))
if response.code.to_i == 200
json = JSON.parse(response.body)
data[url]['last_tag'] = {
'name' => name,
'author_date' => json['commit']['author']['date'],
'committer_date' => json['commit']['committer']['date']
}
else
puts "Invalid response for #{response.uri}: #{response}"
end
end
elsif response.code.to_i != 404
puts "Invalid response for #{response.uri}: #{response}"
end

response = Net::HTTP.get_response(URI("https://api.github.com/repos/#{user}/#{repo}/commits"), hh)

if response.code.to_i == 200
json = JSON.parse(response.body)[0]

if json
data[url]['last_commit'] = {
'author_date' => json['commit']['author']['date'],
'committer_date' => json['commit']['committer']['date']
}
end
else
puts "Invalid response for #{response.uri}: #{response}"
end

if users[user].nil?
response = Net::HTTP.get_response(URI("https://api.github.com/users/#{user}"), hh)

if response.code.to_i == 200
json = JSON.parse(response.body)
users[user] = json
else
puts "Invalid response for #{response.uri}: #{response}"
end
end

data[url]['user_name'] = users[user] && users[user]['name']
else
puts "Invalid response for #{response.uri}: #{response}"
end
else
puts "Skipping #{url}"
end
end

File.write(File.join(__dir__, '_data', 'github_info.yml'), YAML.dump(data))
end
27 changes: 2 additions & 25 deletions _config.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
# Site settings
# These are used to personalize your new site. If you look in the HTML files,
# you will see them accessed via {{ site.title }}, {{ site.email }}, and so on.
# You can create any custom variable you would like, and they will be accessible
# in the templates via {{ site.myvariable }}.

author: "Kuba Suder"
title: "sdk.blue"
description: "A curated list of libraries & SDKs for the Bluesky API and AT Protocol"
Expand All @@ -16,22 +10,5 @@ defaults:
values:
layout: default

# Exclude from processing.
# The following items will not be processed, by default.
# Any item listed under the `exclude:` key here will be automatically added to
# the internal "default list".
#
# Excluded items can be processed by explicitly listing the directories or
# their entries' file path in the `include:` list.
#
# exclude:
# - .sass-cache/
# - .jekyll-cache/
# - gemfiles/
# - Gemfile
# - Gemfile.lock
# - node_modules/
# - vendor/bundle/
# - vendor/cache/
# - vendor/gems/
# - vendor/ruby/
exclude:
- config

0 comments on commit a1ac4cc

Please sign in to comment.