aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2023-09-29 11:54:13 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2023-09-29 11:56:21 +0300
commit205fb9013a3d387478ada8dc30b4da4ec20051a3 (patch)
treec99725eb9fc450095798443fe6a6bb5b3008c12c
parentd3f7242eb9e0476fb0c1d3caf1c6cfdfebab63d1 (diff)
Add support for *-build-*email package manifest values
-rw-r--r--libbrep/build-extra.sql14
-rw-r--r--libbrep/build-package.hxx4
-rw-r--r--libbrep/build.hxx2
-rw-r--r--libbrep/build.xml2
-rw-r--r--libbrep/common.hxx7
-rw-r--r--libbrep/package.hxx15
-rw-r--r--libbrep/package.xml11
-rw-r--r--mod/mod-build-result.cxx91
8 files changed, 84 insertions, 62 deletions
diff --git a/libbrep/build-extra.sql b/libbrep/build-extra.sql
index b1bd04f..9ffbac1 100644
--- a/libbrep/build-extra.sql
+++ b/libbrep/build-extra.sql
@@ -61,6 +61,12 @@ CREATE FOREIGN TABLE build_package (
version_upstream TEXT NOT NULL,
version_release TEXT NULL,
project CITEXT NOT NULL,
+ build_email TEXT NULL,
+ build_email_comment TEXT NULL,
+ build_warning_email TEXT NULL,
+ build_warning_email_comment TEXT NULL,
+ build_error_email TEXT NULL,
+ build_error_email_comment TEXT NULL,
internal_repository_tenant TEXT NULL,
internal_repository_canonical_name TEXT NULL,
buildable BOOLEAN NOT NULL)
@@ -189,7 +195,13 @@ CREATE FOREIGN TABLE build_package_configs (
index BIGINT NOT NULL,
config_name TEXT NOT NULL,
config_arguments TEXT NULL,
- config_comment TEXT NOT NULL)
+ config_comment TEXT NOT NULL,
+ config_email TEXT NULL,
+ config_email_comment TEXT NULL,
+ config_warning_email TEXT NULL,
+ config_warning_email_comment TEXT NULL,
+ config_error_email TEXT NULL,
+ config_error_email_comment TEXT NULL)
SERVER package_server OPTIONS (table_name 'package_build_configs');
CREATE FOREIGN TABLE build_package_config_builds (
diff --git a/libbrep/build-package.hxx b/libbrep/build-package.hxx
index 50294a3..94ffb08 100644
--- a/libbrep/build-package.hxx
+++ b/libbrep/build-package.hxx
@@ -114,6 +114,10 @@ namespace brep
package_name project;
+ optional<email> build_email;
+ optional<email> build_warning_email;
+ optional<email> build_error_email;
+
// Mapped to the package object requirements and tests members using the
// PostgreSQL foreign table mechanism.
//
diff --git a/libbrep/build.hxx b/libbrep/build.hxx
index 717029d..b64b28a 100644
--- a/libbrep/build.hxx
+++ b/libbrep/build.hxx
@@ -28,7 +28,7 @@
//
#define LIBBREP_BUILD_SCHEMA_VERSION_BASE 20
-#pragma db model version(LIBBREP_BUILD_SCHEMA_VERSION_BASE, 21, closed)
+#pragma db model version(LIBBREP_BUILD_SCHEMA_VERSION_BASE, 22, closed)
// We have to keep these mappings at the global scope instead of inside the
// brep namespace because they need to be also effective in the bbot namespace
diff --git a/libbrep/build.xml b/libbrep/build.xml
index 0374b05..2ac0002 100644
--- a/libbrep/build.xml
+++ b/libbrep/build.xml
@@ -1,4 +1,6 @@
<changelog xmlns="http://www.codesynthesis.com/xmlns/odb/changelog" database="pgsql" schema-name="build" version="1">
+ <changeset version="22"/>
+
<changeset version="21"/>
<model version="20">
diff --git a/libbrep/common.hxx b/libbrep/common.hxx
index 158690e..fec22e8 100644
--- a/libbrep/common.hxx
+++ b/libbrep/common.hxx
@@ -333,6 +333,13 @@ namespace brep
#pragma db value(build_constraint) definition
+ // email
+ //
+ using bpkg::email;
+
+ #pragma db value(email) definition
+ #pragma db member(email::value) virtual(string) before access(this) column("")
+
// build_package_config
//
using build_package_config = bpkg::build_package_config;
diff --git a/libbrep/package.hxx b/libbrep/package.hxx
index 4cbdded..e189339 100644
--- a/libbrep/package.hxx
+++ b/libbrep/package.hxx
@@ -20,7 +20,7 @@
//
#define LIBBREP_PACKAGE_SCHEMA_VERSION_BASE 27
-#pragma db model version(LIBBREP_PACKAGE_SCHEMA_VERSION_BASE, 27, closed)
+#pragma db model version(LIBBREP_PACKAGE_SCHEMA_VERSION_BASE, 28, closed)
namespace brep
{
@@ -72,13 +72,6 @@ namespace brep
set(this = brep::manifest_url ((?), "" /* comment */)) \
column("")
- // email
- //
- using bpkg::email;
-
- #pragma db value(email) definition
- #pragma db member(email::value) virtual(string) before access(this) column("")
-
// licenses
//
using bpkg::licenses;
@@ -527,9 +520,9 @@ namespace brep
optional<manifest_url> package_url;
optional<email_type> email;
optional<email_type> package_email;
- optional<email_type> build_email;
- optional<email_type> build_warning_email;
- optional<email_type> build_error_email;
+ optional<email_type> build_email; // Note: foreign-mapped in build.
+ optional<email_type> build_warning_email; // Note: foreign-mapped in build.
+ optional<email_type> build_error_email; // Note: foreign-mapped in build.
dependencies_type dependencies;
requirements_type requirements; // Note: foreign-mapped in build.
small_vector<test_dependency, 1> tests; // Note: foreign-mapped in build.
diff --git a/libbrep/package.xml b/libbrep/package.xml
index 98c9055..073fbb6 100644
--- a/libbrep/package.xml
+++ b/libbrep/package.xml
@@ -1,4 +1,15 @@
<changelog xmlns="http://www.codesynthesis.com/xmlns/odb/changelog" database="pgsql" schema-name="package" version="1">
+ <changeset version="28">
+ <alter-table name="package_build_configs">
+ <add-column name="config_email" type="TEXT" null="true"/>
+ <add-column name="config_email_comment" type="TEXT" null="true"/>
+ <add-column name="config_warning_email" type="TEXT" null="true"/>
+ <add-column name="config_warning_email_comment" type="TEXT" null="true"/>
+ <add-column name="config_error_email" type="TEXT" null="true"/>
+ <add-column name="config_error_email_comment" type="TEXT" null="true"/>
+ </alter-table>
+ </changeset>
+
<model version="27">
<table name="tenant" kind="object">
<column name="id" type="TEXT" null="false"/>
diff --git a/mod/mod-build-result.cxx b/mod/mod-build-result.cxx
index 71cc59a..24b518d 100644
--- a/mod/mod-build-result.cxx
+++ b/mod/mod-build-result.cxx
@@ -51,13 +51,8 @@ init (scanner& s)
s, unknown_mode::fail, unknown_mode::fail);
if (options_->build_config_specified ())
- {
build_result_module::init (*options_, *options_);
- database_module::init (static_cast<const options::package_db&> (*options_),
- options_->package_db_retry ());
- }
-
if (options_->root ().empty ())
options_->root (dir_path ("/"));
}
@@ -168,27 +163,6 @@ handle (request& rq, response&)
tc = i->second;
}
- // Load the built package (if present).
- //
- // The only way not to deal with 2 databases simultaneously is to pull
- // another bunch of the package fields into the build_package foreign
- // object, which is a pain (see build_package.hxx for details). Doesn't seem
- // worth it here: email members are really secondary and we don't need to
- // switch transactions back and forth.
- //
- shared_ptr<package> pkg;
- {
- transaction t (package_db_->begin ());
- pkg = package_db_->find<package> (id.package);
- t.commit ();
- }
-
- if (pkg == nullptr)
- {
- warn_expired ("no package");
- return true;
- }
-
auto print_args = [&trace, this] (const char* args[], size_t n)
{
l2 ([&]{trace << process_args {args, n};});
@@ -202,6 +176,13 @@ handle (request& rq, response&)
//
shared_ptr<build> bld;
+ // The built package configuration.
+ //
+ // Not NULL if bld is not NULL.
+ //
+ shared_ptr<build_package> pkg;
+ const build_package_config* cfg (nullptr);
+
bool build_notify (false);
bool unforced (true);
@@ -374,30 +355,29 @@ handle (request& rq, response&)
build_db_->update (b);
- // Don't send the build notification email if the task result is
- // `skip`, the configuration is hidden, or is now excluded by the
- // package.
+ pkg = build_db_->load<build_package> (b->id.package);
+ cfg = find (b->package_config_name, pkg->configs);
+
+ // The package configuration should be present (see mod-builds.cxx for
+ // details) but if it is not, let's log the warning.
//
- if (rs != result_status::skip && !belongs (*tc, "hidden"))
+ if (cfg != nullptr)
{
- shared_ptr<build_package> p (
- build_db_->load<build_package> (b->id.package));
-
- // The package configuration should be present (see mod-builds.cxx
- // for details) but if it is not, let's log the warning.
+ // Don't send the build notification email if the task result is
+ // `skip`, the configuration is hidden, or is now excluded by the
+ // package.
//
- if (const build_package_config* pc = find (b->package_config_name,
- p->configs))
+ if (rs != result_status::skip && !belongs (*tc, "hidden"))
{
- build_db_->load (*p, p->constraints_section);
+ build_db_->load (*pkg, pkg->constraints_section);
- if (!exclude (*pc, p->builds, p->constraints, *tc))
+ if (!exclude (*cfg, pkg->builds, pkg->constraints, *tc))
bld = move (b);
}
- else
- warn << "cannot find configuration '" << b->package_config_name
- << "' for package " << p->id.name << '/' << p->version;
}
+ else
+ warn << "cannot find configuration '" << b->package_config_name
+ << "' for package " << pkg->id.name << '/' << pkg->version;
}
}
@@ -486,19 +466,32 @@ handle (request& rq, response&)
// Send the build notification email if a non-empty package build email is
// specified.
//
- optional<email>& build_email (pkg->build_email);
- if (build_notify && build_email && !build_email->empty ())
- send_email (*pkg->build_email);
+ if (build_notify)
+ {
+ if (const optional<email>& e = cfg->effective_email (pkg->build_email))
+ {
+ if (!e->empty ())
+ send_email (*pkg->build_email);
+ }
+ }
assert (bld->status);
// Send the build warning/error notification emails, if requested.
//
- if (pkg->build_warning_email && *bld->status >= result_status::warning)
- send_email (*pkg->build_warning_email);
+ if (*bld->status >= result_status::warning)
+ {
+ if (const optional<email>& e =
+ cfg->effective_warning_email (pkg->build_warning_email))
+ send_email (*e);
+ }
- if (pkg->build_error_email && *bld->status >= result_status::error)
- send_email (*pkg->build_error_email);
+ if (*bld->status >= result_status::error)
+ {
+ if (const optional<email>& e =
+ cfg->effective_error_email (pkg->build_error_email))
+ send_email (*e);
+ }
return true;
}