Browse Source

Improve get_latest_github_release

Jasper van Merle 6 năm trước cách đây
mục cha
commit
7084d9f082

+ 1 - 1
docs/scraper-reference.md

@@ -212,7 +212,7 @@ To make life easier, there are a few utility methods that you can use in `get_la
   Example: [lib/docs/scrapers/bower.rb](../lib/docs/scrapers/bower.rb)
 * `get_latest_github_release(owner, repo, opts)`
 
-  Returns the latest GitHub release of the given repository ([format](https://developer.github.com/v3/repos/releases/#get-the-latest-release)).
+  Returns the tag name of the latest GitHub release of the given repository. If the tag name is preceeded by a "v", the "v" will be removed.
 
   Example: [lib/docs/scrapers/jsdoc.rb](../lib/docs/scrapers/jsdoc.rb)
 * `get_github_tags(owner, repo, opts)`

+ 3 - 1
lib/docs/core/doc.rb

@@ -249,7 +249,9 @@ module Docs
     end
 
     def get_latest_github_release(owner, repo, opts)
-      fetch_json("https://api.github.com/repos/#{owner}/#{repo}/releases/latest", opts)
+      release = fetch_json("https://api.github.com/repos/#{owner}/#{repo}/releases/latest", opts)
+      tag_name = release['tag_name']
+      tag_name.start_with?('v') ? tag_name[1..-1] : tag_name
     end
 
     def get_github_tags(owner, repo, opts)

+ 1 - 1
lib/docs/scrapers/homebrew.rb

@@ -21,7 +21,7 @@ module Docs
     HTML
 
     def get_latest_version(opts)
-      get_latest_github_release('Homebrew', 'brew', opts)['name']
+      get_latest_github_release('Homebrew', 'brew', opts)
     end
   end
 end

+ 1 - 1
lib/docs/scrapers/jasmine.rb

@@ -19,7 +19,7 @@ module Docs
     HTML
 
     def get_latest_version(opts)
-      get_latest_github_release('jasmine', 'jasmine', opts)['name']
+      get_latest_github_release('jasmine', 'jasmine', opts)
     end
   end
 end

+ 1 - 1
lib/docs/scrapers/jsdoc.rb

@@ -23,7 +23,7 @@ module Docs
     HTML
 
     def get_latest_version(opts)
-      get_latest_github_release('jsdoc3', 'jsdoc', opts)['tag_name']
+      get_latest_github_release('jsdoc3', 'jsdoc', opts)
     end
   end
 end

+ 1 - 1
lib/docs/scrapers/julia.rb

@@ -51,7 +51,7 @@ module Docs
     end
 
     def get_latest_version(opts)
-      get_latest_github_release('JuliaLang', 'julia', opts)['tag_name'][1..-1]
+      get_latest_github_release('JuliaLang', 'julia', opts)
     end
   end
 end

+ 1 - 1
lib/docs/scrapers/knockout.rb

@@ -35,7 +35,7 @@ module Docs
     HTML
 
     def get_latest_version(opts)
-      get_latest_github_release('knockout', 'knockout', opts)['tag_name'][1..-1]
+      get_latest_github_release('knockout', 'knockout', opts)
     end
   end
 end

+ 1 - 1
lib/docs/scrapers/kotlin.rb

@@ -30,7 +30,7 @@ module Docs
     HTML
 
     def get_latest_version(opts)
-      get_latest_github_release('JetBrains', 'kotlin', opts)['tag_name'][1..-1]
+      get_latest_github_release('JetBrains', 'kotlin', opts)
     end
   end
 end

+ 1 - 1
lib/docs/scrapers/laravel.rb

@@ -135,7 +135,7 @@ module Docs
     end
 
     def get_latest_version(opts)
-      get_latest_github_release('laravel', 'laravel', opts)['tag_name'][1..-1]
+      get_latest_github_release('laravel', 'laravel', opts)
     end
   end
 end

+ 1 - 1
lib/docs/scrapers/matplotlib.rb

@@ -66,7 +66,7 @@ module Docs
     end
 
     def get_latest_version(opts)
-      get_latest_github_release('matplotlib', 'matplotlib', opts)['tag_name'][1..-1]
+      get_latest_github_release('matplotlib', 'matplotlib', opts)
     end
   end
 end

+ 1 - 1
lib/docs/scrapers/nokogiri2.rb

@@ -21,7 +21,7 @@ module Docs
     HTML
 
     def get_latest_version(opts)
-      get_latest_github_release('sparklemotion', 'nokogiri', opts)['tag_name'][1..-1]
+      get_latest_github_release('sparklemotion', 'nokogiri', opts)
     end
   end
 end

+ 1 - 1
lib/docs/scrapers/npm.rb

@@ -31,7 +31,7 @@ module Docs
     HTML
 
     def get_latest_version(opts)
-      get_latest_github_release('npm', 'cli', opts)['tag_name'][1..-1]
+      get_latest_github_release('npm', 'cli', opts)
     end
   end
 end

+ 1 - 1
lib/docs/scrapers/numpy.rb

@@ -51,7 +51,7 @@ module Docs
     end
 
     def get_latest_version(opts)
-      get_latest_github_release('numpy', 'numpy', opts)['tag_name'][1..-1]
+      get_latest_github_release('numpy', 'numpy', opts)
     end
   end
 end

+ 1 - 1
lib/docs/scrapers/opentsdb.rb

@@ -20,7 +20,7 @@ module Docs
     HTML
 
     def get_latest_version(opts)
-      get_latest_github_release('OpenTSDB', 'opentsdb', opts)['tag_name'][1..-1]
+      get_latest_github_release('OpenTSDB', 'opentsdb', opts)
     end
   end
 end

+ 1 - 1
lib/docs/scrapers/phaser.rb

@@ -27,7 +27,7 @@ module Docs
     HTML
 
     def get_latest_version(opts)
-      get_latest_github_release('photonstorm', 'phaser', opts)['tag_name'][1..-1]
+      get_latest_github_release('photonstorm', 'phaser', opts)
     end
   end
 end

+ 1 - 1
lib/docs/scrapers/pygame.rb

@@ -19,7 +19,7 @@ module Docs
     HTML
 
     def get_latest_version(opts)
-      get_latest_github_release('pygame', 'pygame', opts)['tag_name']
+      get_latest_github_release('pygame', 'pygame', opts)
     end
   end
 end

+ 1 - 1
lib/docs/scrapers/rdoc/rails.rb

@@ -95,7 +95,7 @@ module Docs
     end
 
     def get_latest_version(opts)
-      get_latest_github_release('rails', 'rails', opts)['name']
+      get_latest_github_release('rails', 'rails', opts)
     end
   end
 end

+ 1 - 1
lib/docs/scrapers/rethinkdb.rb

@@ -59,7 +59,7 @@ module Docs
     end
 
     def get_latest_version(opts)
-      get_latest_github_release('rethinkdb', 'rethinkdb', opts)['tag_name'][1..-1]
+      get_latest_github_release('rethinkdb', 'rethinkdb', opts)
     end
 
     private

+ 1 - 1
lib/docs/scrapers/sass.rb

@@ -25,7 +25,7 @@ module Docs
     HTML
 
     def get_latest_version(opts)
-      get_latest_github_release('sass', 'libsass', opts)['tag_name']
+      get_latest_github_release('sass', 'libsass', opts)
     end
   end
 end

+ 1 - 1
lib/docs/scrapers/symfony.rb

@@ -72,7 +72,7 @@ module Docs
     end
 
     def get_latest_version(opts)
-      get_latest_github_release('symfony', 'symfony', opts)['tag_name'][1..-1]
+      get_latest_github_release('symfony', 'symfony', opts)
     end
   end
 end

+ 1 - 1
lib/docs/scrapers/tensorflow.rb

@@ -57,7 +57,7 @@ module Docs
     end
 
     def get_latest_version(opts)
-      get_latest_github_release('tensorflow', 'tensorflow', opts)['tag_name'][1..-1]
+      get_latest_github_release('tensorflow', 'tensorflow', opts)
     end
 
     private

+ 1 - 1
lib/docs/scrapers/typescript.rb

@@ -26,7 +26,7 @@ module Docs
     HTML
 
     def get_latest_version(opts)
-      get_latest_github_release('Microsoft', 'TypeScript', opts)['tag_name'][1..-1]
+      get_latest_github_release('Microsoft', 'TypeScript', opts)
     end
   end
 end

+ 1 - 1
lib/docs/scrapers/vue.rb

@@ -34,7 +34,7 @@ module Docs
     end
 
     def get_latest_version(opts)
-      get_latest_github_release('vuejs', 'vue', opts)['tag_name'][1..-1]
+      get_latest_github_release('vuejs', 'vue', opts)
     end
   end
 end

+ 1 - 1
lib/docs/scrapers/yarn.rb

@@ -22,7 +22,7 @@ module Docs
     HTML
 
     def get_latest_version(opts)
-      get_latest_github_release('yarnpkg', 'yarn', opts)['tag_name'][1..-1]
+      get_latest_github_release('yarnpkg', 'yarn', opts)
     end
   end
 end

+ 1 - 1
lib/docs/scrapers/yii.rb

@@ -36,7 +36,7 @@ module Docs
     end
 
     def get_latest_version(opts)
-      get_latest_github_release('yiisoft', 'yii2', opts)['tag_name']
+      get_latest_github_release('yiisoft', 'yii2', opts)
     end
   end
 end