1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/zhousiwei-zhousiwei

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Клонировать/Скачать
自动初始化Gitment评论(实现中).sh 1.9 КБ
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
zhousiwei Отправлено 10.05.2019 05:00 d30d3c7
# from : https://madordie.github.io/post/blog-gitment-auto-setup
# 另外,token已放在.git-token文件下,并被.gitignore标记,防止泄漏。。
username = "madordie" # GitHub 用户名
token = `cat .git-token` # GitHub Token
repo_name = "madordie.github.io" # 存放 issues
sitemap_url = "https://madordie.github.io/sitemap.xml" # sitemap
kind = "gitment" # "Gitalk" or "gitment"
require 'open-uri'
require 'faraday'
require 'active_support'
require 'active_support/core_ext'
require 'sitemap-parser'
require 'digest'
puts "正在检索URL"
sitemap = SitemapParser.new sitemap_url
urls = sitemap.to_a
puts "检索到文章共#{urls.count}个"
conn = Faraday.new(:url => "https://api.github.com") do |conn|
conn.basic_auth(username, token)
conn.headers['Accept'] = "application/vnd.github.symmetra-preview+json"
conn.adapter Faraday.default_adapter
end
commenteds = Array.new
`
if [ ! -f .commenteds ]; then
touch .commenteds
fi
`
File.open(".commenteds", "r") do |file|
file.each_line do |line|
commenteds.push line
end
end
urls.each_with_index do |url, index|
url.gsub!(/index.html$/, "")
if commenteds.include?("#{url}\n") == false
url_key = Digest::MD5.hexdigest(URI.parse(url).path)
response = conn.get "/search/issues?q=label:#{url_key}+state:open+repo:#{username}/#{repo_name}"
if JSON.parse(response.body)['total_count'] > 0
`echo #{url} >> .commenteds`
else
puts "正在创建: #{url}"
title = open(url).read.scan(/<title>(.*?)<\/title>/).first.first.force_encoding('UTF-8')
response = conn.post("/repos/#{username}/#{repo_name}/issues") do |req|
req.body = { body: url, labels: [kind, url_key], title: title }.to_json
end
if JSON.parse(response.body)['number'] > 0
`echo #{url} >> .commenteds`
puts "\t↳ 已创建成功"
else
puts "\t↳ #{response.body}"
end
end
end
end

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://api.gitlife.ru/oschina-mirror/zhousiwei-zhousiwei.git
git@api.gitlife.ru:oschina-mirror/zhousiwei-zhousiwei.git
oschina-mirror
zhousiwei-zhousiwei
zhousiwei-zhousiwei
master