From 7e7dee76c870917866fd23f385211ee8101705b4 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 22 Aug 2018 19:34:51 +0200 Subject: Add support for specifying publisher's name in addition to email --- bdep/new.cli | 8 ++--- bdep/new.cxx | 4 +-- bdep/project-author.cxx | 87 +++++++++++++++++++++++++++++++++++++++++++++++++ bdep/project-author.hxx | 41 +++++++++++++++++++++++ bdep/project-email.cxx | 70 --------------------------------------- bdep/project-email.hxx | 23 ------------- bdep/publish.cli | 30 +++++++++++------ bdep/publish.cxx | 47 +++++++++++++++++--------- tests/publish.test | 3 +- 9 files changed, 188 insertions(+), 125 deletions(-) create mode 100644 bdep/project-author.cxx create mode 100644 bdep/project-author.hxx delete mode 100644 bdep/project-email.cxx delete mode 100644 bdep/project-email.hxx diff --git a/bdep/new.cli b/bdep/new.cli index b188af9..d7e3ed0 100644 --- a/bdep/new.cli +++ b/bdep/new.cli @@ -260,10 +260,10 @@ namespace bdep "\h|ENVIRONMENT| - The \cb{BDEP_EMAIL} environment variable can be used to specify the package - email address. If not set, the \cb{new} command will first try to obtain - the email from the version control system (if used) and then from the - \cb{EMAIL} environment variable. If all these methods fail, a dummy + The \cb{BDEP_AUTHOR_EMAIL} environment variable can be used to specify the + package email address. If not set, the \cb{new} command will first try to + obtain the email from the version control system (if used) and then from + the \cb{EMAIL} environment variable. If all these methods fail, a dummy \cb{@example.org} email is used. " } diff --git a/bdep/new.cxx b/bdep/new.cxx index 64e1724..45c3234 100644 --- a/bdep/new.cxx +++ b/bdep/new.cxx @@ -7,7 +7,7 @@ #include #include -#include +#include #include #include @@ -370,7 +370,7 @@ namespace bdep // string email; { - optional r (project_email (prj)); + optional r (find_project_author_email (prj)); email = r ? move (*r) : "you@example.org"; } diff --git a/bdep/project-author.cxx b/bdep/project-author.cxx new file mode 100644 index 0000000..7aa1eb9 --- /dev/null +++ b/bdep/project-author.cxx @@ -0,0 +1,87 @@ +// file : bdep/project-author.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2018 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include + +#include +#include + +using namespace butl; + +namespace bdep +{ + project_author + find_project_author (const dir_path& prj) + { + project_author r; + + // The search order is as follows: + // + // BDEP_AUTHOR_(NAME|EMAIL) + // + // (USER|EMAIL) + // + r.name = getenv ("BDEP_AUTHOR_NAME"); + r.email = getenv ("BDEP_AUTHOR_EMAIL"); + + if (!r.name || !r.email) + { + // See if this is a VCS repository we recognize. + // + if (git_repository (prj)) + { + // In git the author name/email can be specified with the + // GIT_AUTHOR_NAME/EMAIL environment variables after which things + // fall back to the committer (GIT_COMMITTER_NAME/EMAIL and then + // the user.name/email git-config value). The resolved value can + // be queried with the GIT_AUTHOR_IDENT logical variable. + // + if (optional l = git_line (semantic_version {2, 1, 0}, + prj, + true /* ignore_error */, + "var", "GIT_AUTHOR_IDENT")) + { + // The output should be a single line in this form: + // + // NAME TIME ZONE + // + // For example: + // + // John Doe 1530517726 +0200 + // + // The <> delimiters are there even if the email is empty so we use + // them as anchors. + // + size_t p1, p2; + + if ((p2 = l->rfind ('>' )) == string::npos || + (p1 = l->rfind ('<', p2)) == string::npos) + fail << "invalid GIT_AUTHOR_IDENT value '" << *l << "'" << endf; + + if (!r.name) + { + string n (*l, 0, p1); + + if (!trim (n).empty ()) + r.name = move (n); + } + + if (!r.email) + { + ++p1; + string e (*l, p1, p2 - p1); + + if (!trim (e).empty ()) + r.email = move (e); + } + } + } + } + + if (!r.name ) r.name = getenv ("USER"); + if (!r.email) r.email = getenv ("EMAIL"); + + return r; + } +} diff --git a/bdep/project-author.hxx b/bdep/project-author.hxx new file mode 100644 index 0000000..bcabdb3 --- /dev/null +++ b/bdep/project-author.hxx @@ -0,0 +1,41 @@ +// file : bdep/project-author.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2018 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BDEP_PROJECT_AUTHOR_HXX +#define BDEP_PROJECT_AUTHOR_HXX + +#include +#include + +namespace bdep +{ + // Given a project directly, try to discover the author's name/email address + // using the environment and, if project looks like a repository, its VCS. + // + // Note: if using this function in a command, don't forget to update its + // ENVIRONMENT section to mention BDEP_AUTHOR_{NAME,EMAIL}. + // + struct project_author + { + optional name; + optional email; + }; + + project_author + find_project_author (const dir_path&); + + inline optional + find_project_author_name (const dir_path& d) + { + return find_project_author (d).name; + } + + inline optional + find_project_author_email (const dir_path& d) + { + return find_project_author (d).email; + } +} + +#endif // BDEP_PROJECT_AUTHOR_HXX diff --git a/bdep/project-email.cxx b/bdep/project-email.cxx deleted file mode 100644 index fe43b18..0000000 --- a/bdep/project-email.cxx +++ /dev/null @@ -1,70 +0,0 @@ -// file : bdep/project-email.cxx -*- C++ -*- -// copyright : Copyright (c) 2014-2018 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#include - -#include -#include - -using namespace butl; - -namespace bdep -{ - optional - project_email (const dir_path& prj) - { - optional r; - - // The search order is as follows: - // - // BDEP_EMAIL - // - // EMAIL - // - if ((r = getenv ("BDEP_EMAIL"))) - return r; - - // See if this is a VCS repository we recognize. - // - if (git_repository (prj)) - { - // In git the author email can be specified with the GIT_AUTHOR_EMAIL - // environment variable after which things fall back to the committer - // (GIT_COMMITTER_EMAIL and then the user.email git-config value). The - // resolved value can be queried with the GIT_AUTHOR_IDENT logical - // variable. - // - if (optional l = git_line (semantic_version {2, 1, 0}, - prj, - true /* ignore_error */, - "var", "GIT_AUTHOR_IDENT")) - { - // The output should be a single line in this form: - // - // NAME TIME ZONE - // - // For example: - // - // John Doe 1530517726 +0200 - // - // The <> delimiters are there even if the email is empty so we use - // them as anchors. - // - size_t p1, p2; - - if ((p2 = l->rfind ('>' )) == string::npos || - (p1 = l->rfind ('<', p2)) == string::npos) - fail << "no email in GIT_AUTHOR_IDENT" << endf; - - if (++p1 != p2) - return string (*l, p1, p2 - p1); - } - } - - if ((r = getenv ("EMAIL"))) - return r; - - return r; - } -} diff --git a/bdep/project-email.hxx b/bdep/project-email.hxx deleted file mode 100644 index c630682..0000000 --- a/bdep/project-email.hxx +++ /dev/null @@ -1,23 +0,0 @@ -// file : bdep/project-email.hxx -*- C++ -*- -// copyright : Copyright (c) 2014-2018 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#ifndef BDEP_PROJECT_EMAIL_HXX -#define BDEP_PROJECT_EMAIL_HXX - -#include -#include - -namespace bdep -{ - // Given a project directly, try to discover the author's email address - // using the environment and, if project looks like a repository, its VCS. - // - // Note: if using this function in a command, don't forget to update its - // ENVIRONMENT section to mention BDEP_EMAIL. - // - optional - project_email (const dir_path&); -} - -#endif // BDEP_PROJECT_EMAIL_HXX diff --git a/bdep/publish.cli b/bdep/publish.cli index fce6a23..bcbb022 100644 --- a/bdep/publish.cli +++ b/bdep/publish.cli @@ -45,8 +45,8 @@ namespace bdep Along with the package archive, the submission request specifies the project the package belongs to, the repository section to publish the package under, the control repository URL to use for authorization, and - the publisher's email address for notifications. While the exact usage - and interpretation of this information depends on the specific + the publisher's name and email address for the record. While the exact + usage and interpretation of this information depends on the specific repository, the following semantics apply when submitting to \cb{cppget.org}. @@ -113,12 +113,20 @@ namespace bdep "Repository section to publish the packages under." } - string --email + string --author-name + { + "", + "Publisher's name. If unspecified, it will be obtained from the + environment and/or version control system. See the ENVIRONMENT + section for details." + } + + string --author-email { "", - "Publisher's email address for notifications. If unspecified, one will be - obtained from the environment and/or version control system. See the - ENVIRONMENT section for details." + "Publisher's email address. If unspecified, it will be obtained from the + environment and/or version control system. See the ENVIRONMENT section + for details." } string --simulate @@ -134,9 +142,11 @@ namespace bdep "\h|ENVIRONMENT| - The \cb{BDEP_EMAIL} environment variable can be used to specify the - publisher's email address. If not set, the \cb{publish} command will first - try to obtain the email from the version control system (if used) and then - from the \cb{EMAIL} environment variable. See also the \cb{--email} option. + The \cb{BDEP_AUTHOR_NAME} and \cb{BDEP_AUTHOR_EMAIL} environment variables + can be used to specify the publisher's name and email address, + respectively. If not set, the \cb{publish} command will first try to obtain + the name and email from the version control system (if used) and then from + the \cb{USER} and \cb{EMAIL} environment variables, respectively. See also + the \cb{--author-name} and \cb{--author-email} options. " } diff --git a/bdep/publish.cxx b/bdep/publish.cxx index adda05b..00fc003 100644 --- a/bdep/publish.cxx +++ b/bdep/publish.cxx @@ -15,7 +15,7 @@ #include #include -#include +#include #include #include @@ -249,7 +249,7 @@ namespace bdep const path& archive, const string& checksum, const string& section, - const string& email, + const project_author& author, const optional& ctrl) { using parser = manifest_parser; @@ -338,10 +338,11 @@ namespace bdep // "--include", - "--form", "archive=@" + archive.string (), - "--form-string", "sha256sum=" + checksum, - "--form-string", "section=" + section, - "--form-string", "email=" + email, + "--form", "archive=@" + archive.string (), + "--form-string", "sha256sum=" + checksum, + "--form-string", "section=" + section, + "--form-string", "author-name=" + *author.name, + "--form-string", "author-email=" + *author.email, ctrl ? strings ({"--form-string", "control=" + ctrl->string ()}) @@ -694,6 +695,8 @@ namespace bdep const url& repo (o.repository ()); + // Control repository URL. + // optional ctrl; if (o.control_specified ()) { @@ -703,14 +706,28 @@ namespace bdep else ctrl = control_url (prj); - string email; - if (o.email_specified ()) - email = o.email (); - else if (optional r = project_email (prj)) - email = move (*r); - else + // Publisher's name/email. + // + project_author author; + + if (o.author_name_specified ()) author.name = o.author_name (); + if (o.author_email_specified ()) author.email = o.author_email (); + + if (!author.name || !author.email) + { + project_author a (find_project_author (prj)); + + if (!author.name) author.name = move (a.name); + if (!author.email) author.email = move (a.email); + } + + if (!author.name || author.name->empty ()) + fail << "unable to obtain publisher's name" << + info << "use --author-name to specify explicitly"; + + if (!author.email || author.email->empty ()) fail << "unable to obtain publisher's email" << - info << "use --email to specify explicitly"; + info << "use --author-email to specify explicitly"; // Collect package information (version, project, section, archive // path/checksum, and manifest). @@ -768,7 +785,7 @@ namespace bdep { text << "publishing:" << '\n' << " to: " << repo << '\n' - << " as: " << email + << " as: " << *author.name << " <" << *author.email << '>' << '\n'; for (size_t i (0); i != pkgs.size (); ++i) @@ -1318,7 +1335,7 @@ namespace bdep text << "submitting " << p.archive.leaf (); pair r ( - submit (o, p.archive, p.checksum, p.section, email, ctrl)); + submit (o, p.archive, p.checksum, p.section, author, ctrl)); if (verb) text << r.second << " (" << r.first << ")"; diff --git a/tests/publish.test b/tests/publish.test index 663066f..61f7a60 100644 --- a/tests/publish.test +++ b/tests/publish.test @@ -23,7 +23,8 @@ repository = ($config.bdep.test.repository == [null] \ : 'https://cppget.org') \ : "$config.bdep.test.repository") -test.arguments += --repository "$repository" --yes --email user@example.com +test.arguments += --repository "$repository" --yes \ + --author-name user --author-email user@example.com cxx = cc "config.cxx=$config.cxx" -- cgit v1.1