Skip to content

Allow overriding the OPL metadata release API URL via an environment variable#3057

Open
xcompass wants to merge 1 commit into
openwebwork:WeBWorK-2.21from
ubc:upstream-opl-metadata-url-env-override
Open

Allow overriding the OPL metadata release API URL via an environment variable#3057
xcompass wants to merge 1 commit into
openwebwork:WeBWorK-2.21from
ubc:upstream-opl-metadata-url-env-override

Conversation

@xcompass

Copy link
Copy Markdown
Member

Summary

bin/download-OPL-metadata-release.pl hardcodes the GitHub API URL used to locate the latest OPL metadata release (https://api.github.com/repos/openwebwork/webwork-open-problem-library/releases/latest). Sites that maintain a fork of the webwork-open-problem-library (for example, to carry local problems and publish their own metadata releases) cannot use the script against their fork without patching it.

This change allows the release API URL to be overridden by setting the OPL_METADATA_RELEASE_API_URL environment variable:

OPL_METADATA_RELEASE_API_URL=https://api.github.com/repos/<org>/webwork-open-problem-library/releases/latest \
    ./bin/download-OPL-metadata-release.pl

When the variable is not set, the script behaves exactly as before, using the openwebwork URL. The rest of the fetch/decode/restore logic is untouched, and a brief comment documents the override at the point of use.

Testing

  • Ran perltidy v20260204 (the version pinned in .github/workflows/check-formats.yml) with the repository .perltidyrc; the committed file is idempotent under it.
  • perl -c passes on the full script (checked with the script's WeBWorK/Helper module dependencies stubbed, since compiling those requires a full runtime environment).
  • Verified the default (variable unset) resolves to the same openwebwork URL string as before the change, so existing installations see no behavior change.

Dependencies: none.

@drgrice1 drgrice1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is questionable if this should be accepted. Should we support using external repositories for the OPL? Those that are maintaining these repositories should submit their problems to the actual OPL instead. There are other methods for using external libraries for problems that can be used.

This will need discussion.

Comment thread bin/download-OPL-metadata-release.pl Outdated
Comment on lines +35 to +42
# Set the OPL_METADATA_RELEASE_API_URL environment variable to override the release API URL,
# for example, for sites that use a fork of the OPL.
my $releaseApiUrl = $ENV{OPL_METADATA_RELEASE_API_URL}
// 'https://api.github.com/repos/openwebwork/webwork-open-problem-library/releases/latest';
my $releaseDataFF = File::Fetch->new(uri => $releaseApiUrl);
my $file = $releaseDataFF->fetch(to => $ce->{webworkDirs}{tmp}) or die $releaseDataFF->error;
my $path = Mojo::File->new($file);
my $releaseData = decode_json($path->slurp);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change this to

Suggested change
# Set the OPL_METADATA_RELEASE_API_URL environment variable to override the release API URL,
# for example, for sites that use a fork of the OPL.
my $releaseApiUrl = $ENV{OPL_METADATA_RELEASE_API_URL}
// 'https://api.github.com/repos/openwebwork/webwork-open-problem-library/releases/latest';
my $releaseDataFF = File::Fetch->new(uri => $releaseApiUrl);
my $file = $releaseDataFF->fetch(to => $ce->{webworkDirs}{tmp}) or die $releaseDataFF->error;
my $path = Mojo::File->new($file);
my $releaseData = decode_json($path->slurp);
# Set the OPL_METADATA_RELEASE_API_URL environment variable to override the release API URL,
# for example, for sites that use a fork of the OPL.
my $releaseDataFF = File::Fetch->new(uri => $ENV{OPL_METADATA_RELEASE_API_URL}
// 'https://api.github.com/repos/openwebwork/webwork-open-problem-library/releases/latest');
my $file = $releaseDataFF->fetch(to => $ce->{webworkDirs}{tmp}) or die $releaseDataFF->error;
my $path = Mojo::File->new($file);
my $releaseData = decode_json($path->slurp);

There is no need for the intermediate $releaseApiUrl variable that is only used once. Just put its value in the one place it is used.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done — applied your suggestion; the $ENV{OPL_METADATA_RELEASE_API_URL} // ... default is now inlined in the File::Fetch->new call with no intermediate variable.

@xcompass

Copy link
Copy Markdown
Member Author

We have instructors who are not conformable sharing their libraries publicly. So we have to host our own repo. For those are OK with sharing, we let them open PRs to the OPL directly.

The download-OPL-metadata-release.pl script hardcodes the GitHub API URL
used to locate the latest OPL metadata release. Sites that maintain a
fork of the webwork-open-problem-library (for example, with local
problem metadata) cannot use the script to download their own metadata
releases.

Allow the URL to be overridden by setting the
OPL_METADATA_RELEASE_API_URL environment variable, and fall back to the
existing openwebwork URL when the variable is not set. The rest of the
fetch and restore logic is unchanged.
@xcompass xcompass force-pushed the upstream-opl-metadata-url-env-override branch from 0d87deb to a50909b Compare July 14, 2026 01:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants