0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-05 12:50:27 +08:00
discourse/plugins/discourse-github/spec/lib
Régis Hanol 7fdfa88e11
UX: Name the failing repository in GitHub setting validation errors (#41738)
### Why

Saving `github_linkback_access_token` validates the token against every
repository listed in `github_badges_repos`, and saving
`github_badges_repos` validates the format of each entry. When one entry
failed, both validators returned a generic error:

- _"You must provide a valid GitHub linkback access token which has
access to the badge repositories you have provided."_
- _"You must provide a GitHub URL or the repository name in the format
github_user/repository_name"_

Neither message said **which** repository was at fault. On a site with a
long list of repositories, an admin had no way to identify the offending
entry from the UI and had to run a console script to find it.

### What changed

Both validators now capture the first failing entry and interpolate its
name into the error message, so the problem repository can be fixed
straight from the settings page, e.g.:

> The GitHub linkback access token could not access the
'acme/private-repo' repository. Make sure the token is valid and that
the repository name is correct and accessible.

> 'not a repo' is not a valid GitHub URL or repository name. Use the
format github_user/repository_name.

The generic messages are kept as a fallback.

While reworking the token validator, a repository that is missing or
private (GitHub answers both with a `404`) was previously left unrescued
and turned the save into a `500`. That case is now treated as a
validation failure, alongside an unauthorized (`401`) token, and
reported with the same repository-naming message.

### Testing

Added specs covering the `401` and `404` paths for the token validator
and the "name the first invalid entry" path for the badges-repo
validator, plus the generic-message fallback for both.
2026-07-15 15:46:18 +02:00
..
commits_populator_spec.rb FEATURE: Route all GitHub API requests through one rate-limited client (#40637) 2026-06-15 10:59:10 +02:00
github_badges_repo_setting_validator_spec.rb UX: Name the failing repository in GitHub setting validation errors (#41738) 2026-07-15 15:46:18 +02:00
github_badges_spec.rb
github_linkback_access_token_setting_validator_spec.rb UX: Name the failing repository in GitHub setting validation errors (#41738) 2026-07-15 15:46:18 +02:00
github_linkback_spec.rb FEATURE: Route all GitHub API requests through one rate-limited client (#40637) 2026-06-15 10:59:10 +02:00
github_permalinks_spec.rb
github_pr_onebox_status_spec.rb FEATURE: Private GitHub inline oneboxes (#40393) 2026-06-01 10:42:28 +10:00