Merge pull request #2481 from MikeMcQuaid/create-github-metadata
create: use GitHub metadata where available.
This commit is contained in:
commit
85af8c71c7
@ -10,7 +10,8 @@
|
|||||||
#: If `--meson` is passed, create a basic template for a Meson-style build.
|
#: If `--meson` is passed, create a basic template for a Meson-style build.
|
||||||
#:
|
#:
|
||||||
#: If `--no-fetch` is passed, Homebrew will not download <URL> to the cache and
|
#: If `--no-fetch` is passed, Homebrew will not download <URL> to the cache and
|
||||||
#: will thus not add the SHA256 to the formula for you.
|
#: will thus not add the SHA256 to the formula for you. It will also not check
|
||||||
|
#: the GitHub API for GitHub projects (to fill out the description and homepage).
|
||||||
#:
|
#:
|
||||||
#: The options `--set-name` and `--set-version` each take an argument and allow
|
#: The options `--set-name` and `--set-version` each take an argument and allow
|
||||||
#: you to explicitly set the name and version of the package you are creating.
|
#: you to explicitly set the name and version of the package you are creating.
|
||||||
@ -100,7 +101,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
class FormulaCreator
|
class FormulaCreator
|
||||||
attr_reader :url, :sha256
|
attr_reader :url, :sha256, :desc, :homepage
|
||||||
attr_accessor :name, :version, :tap, :path, :mode
|
attr_accessor :name, :version, :tap, :path, :mode
|
||||||
|
|
||||||
def url=(url)
|
def url=(url)
|
||||||
@ -108,11 +109,15 @@ class FormulaCreator
|
|||||||
path = Pathname.new(url)
|
path = Pathname.new(url)
|
||||||
if @name.nil?
|
if @name.nil?
|
||||||
case url
|
case url
|
||||||
when %r{github\.com/\S+/(\S+)\.git}
|
when %r{github\.com/(\S+)/(\S+)\.git}
|
||||||
@name = $1
|
@user = $1
|
||||||
|
@name = $2
|
||||||
@head = true
|
@head = true
|
||||||
when %r{github\.com/\S+/(\S+)/archive/}
|
@github = true
|
||||||
@name = $1
|
when %r{github\.com/(\S+)/(\S+)/(archive|releases)/}
|
||||||
|
@user = $1
|
||||||
|
@name = $2
|
||||||
|
@github = true
|
||||||
else
|
else
|
||||||
@name = path.basename.to_s[/(.*?)[-_.]?#{Regexp.escape(path.version.to_s)}/, 1]
|
@name = path.basename.to_s[/(.*?)[-_.]?#{Regexp.escape(path.version.to_s)}/, 1]
|
||||||
end
|
end
|
||||||
@ -131,7 +136,7 @@ class FormulaCreator
|
|||||||
end
|
end
|
||||||
|
|
||||||
def fetch?
|
def fetch?
|
||||||
!head? && !ARGV.include?("--no-fetch")
|
!ARGV.include?("--no-fetch")
|
||||||
end
|
end
|
||||||
|
|
||||||
def head?
|
def head?
|
||||||
@ -145,11 +150,25 @@ class FormulaCreator
|
|||||||
opoo "Version cannot be determined from URL."
|
opoo "Version cannot be determined from URL."
|
||||||
puts "You'll need to add an explicit 'version' to the formula."
|
puts "You'll need to add an explicit 'version' to the formula."
|
||||||
elsif fetch?
|
elsif fetch?
|
||||||
r = Resource.new
|
unless head?
|
||||||
r.url(url)
|
r = Resource.new
|
||||||
r.version(version)
|
r.url(url)
|
||||||
r.owner = self
|
r.version(version)
|
||||||
@sha256 = r.fetch.sha256 if r.download_strategy == CurlDownloadStrategy
|
r.owner = self
|
||||||
|
@sha256 = r.fetch.sha256 if r.download_strategy == CurlDownloadStrategy
|
||||||
|
end
|
||||||
|
|
||||||
|
if @user && @name
|
||||||
|
begin
|
||||||
|
metadata = GitHub.repository(@user, @name)
|
||||||
|
@desc = metadata["description"]
|
||||||
|
@homepage = metadata["homepage"]
|
||||||
|
rescue GitHub::HTTPNotFoundError
|
||||||
|
# If there was no repository found assume the network connection is at
|
||||||
|
# fault rather than the input URL.
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
path.write ERB.new(template, nil, ">").result(binding)
|
path.write ERB.new(template, nil, ">").result(binding)
|
||||||
@ -161,8 +180,8 @@ class FormulaCreator
|
|||||||
# PLEASE REMOVE ALL GENERATED COMMENTS BEFORE SUBMITTING YOUR PULL REQUEST!
|
# PLEASE REMOVE ALL GENERATED COMMENTS BEFORE SUBMITTING YOUR PULL REQUEST!
|
||||||
|
|
||||||
class #{Formulary.class_s(name)} < Formula
|
class #{Formulary.class_s(name)} < Formula
|
||||||
desc ""
|
desc "#{desc}"
|
||||||
homepage ""
|
homepage "#{homepage}"
|
||||||
<% if head? %>
|
<% if head? %>
|
||||||
head "#{url}"
|
head "#{url}"
|
||||||
<% else %>
|
<% else %>
|
||||||
|
|||||||
@ -709,7 +709,8 @@ With `--verbose` or `-v`, many commands print extra debugging information. Note
|
|||||||
If `--meson` is passed, create a basic template for a Meson-style build.
|
If `--meson` is passed, create a basic template for a Meson-style build.
|
||||||
|
|
||||||
If `--no-fetch` is passed, Homebrew will not download `URL` to the cache and
|
If `--no-fetch` is passed, Homebrew will not download `URL` to the cache and
|
||||||
will thus not add the SHA256 to the formula for you.
|
will thus not add the SHA256 to the formula for you. It will also not check
|
||||||
|
the GitHub API for GitHub projects (to fill out the description and homepage).
|
||||||
|
|
||||||
The options `--set-name` and `--set-version` each take an argument and allow
|
The options `--set-name` and `--set-version` each take an argument and allow
|
||||||
you to explicitly set the name and version of the package you are creating.
|
you to explicitly set the name and version of the package you are creating.
|
||||||
|
|||||||
@ -729,7 +729,7 @@ Generate a formula for the downloadable file at \fIURL\fR and open it in the edi
|
|||||||
If \fB\-\-autotools\fR is passed, create a basic template for an Autotools\-style build\. If \fB\-\-cmake\fR is passed, create a basic template for a CMake\-style build\. If \fB\-\-meson\fR is passed, create a basic template for a Meson\-style build\.
|
If \fB\-\-autotools\fR is passed, create a basic template for an Autotools\-style build\. If \fB\-\-cmake\fR is passed, create a basic template for a CMake\-style build\. If \fB\-\-meson\fR is passed, create a basic template for a Meson\-style build\.
|
||||||
.
|
.
|
||||||
.IP
|
.IP
|
||||||
If \fB\-\-no\-fetch\fR is passed, Homebrew will not download \fIURL\fR to the cache and will thus not add the SHA256 to the formula for you\.
|
If \fB\-\-no\-fetch\fR is passed, Homebrew will not download \fIURL\fR to the cache and will thus not add the SHA256 to the formula for you\. It will also not check the GitHub API for GitHub projects (to fill out the description and homepage)\.
|
||||||
.
|
.
|
||||||
.IP
|
.IP
|
||||||
The options \fB\-\-set\-name\fR and \fB\-\-set\-version\fR each take an argument and allow you to explicitly set the name and version of the package you are creating\.
|
The options \fB\-\-set\-name\fR and \fB\-\-set\-version\fR each take an argument and allow you to explicitly set the name and version of the package you are creating\.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user