allow custom git domain for GitShield

master
Jean-Christian Paul Denis 2023-08-06 18:43:17 +02:00
parent c7b014072f
commit c699a76fa6
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
1 changed files with 18 additions and 4 deletions

View File

@ -38,6 +38,9 @@ class GitShields extends Task
/** @var string Username of git repo */ /** @var string Username of git repo */
private $username = ''; private $username = '';
/** @var string Domain of git repo */
private $domain = 'github.com';
/** @var boolean add Dotaddict shield */ /** @var boolean add Dotaddict shield */
private $dotaddict = false; private $dotaddict = false;
@ -55,12 +58,12 @@ class GitShields extends Task
/** @var array Shields patterns */ /** @var array Shields patterns */
protected $bloc_content = [ protected $bloc_content = [
'release' => '[![Release](https://img.shields.io/github/v/release/%username%/%module%)](https://github.com/%username%/%module%/releases)', 'release' => '[![Release](https://img.shields.io/github/v/release/%username%/%module%)](https://%domain%/%username%/%module%/releases)',
'date' => '[![Date](https://img.shields.io/github/release-date/%username%/%module%)](https://github.com/%username%/%module%/releases)', 'date' => '[![Date](https://img.shields.io/github/release-date/%username%/%module%)](https://%domain%/%username%/%module%/releases)',
'issues' => '[![Issues](https://img.shields.io/github/issues/%username%/%module%)](https://github.com/%username%/%module%/issues)', 'issues' => '[![Issues](https://img.shields.io/github/issues/%username%/%module%)](https://%domain%/%username%/%module%/issues)',
'dotclear' => '[![Dotclear](https://img.shields.io/badge/dotclear-v%dotclear%-blue.svg)](https://fr.dotclear.org/download)', 'dotclear' => '[![Dotclear](https://img.shields.io/badge/dotclear-v%dotclear%-blue.svg)](https://fr.dotclear.org/download)',
'dotaddict' => '[![Dotaddict](https://img.shields.io/badge/dotaddict-official-green.svg)](https://%type%s.dotaddict.org/dc2/details/%module%)', 'dotaddict' => '[![Dotaddict](https://img.shields.io/badge/dotaddict-official-green.svg)](https://%type%s.dotaddict.org/dc2/details/%module%)',
'license' => '[![License](https://img.shields.io/github/license/%username%/%module%)](https://github.com/%username%/%module%/blob/master/LICENSE)', 'license' => '[![License](https://img.shields.io/github/license/%username%/%module%)](https://%domain%/%username%/%module%/blob/master/LICENSE)',
]; ];
protected function getProperties(): TaskDescriptor protected function getProperties(): TaskDescriptor
@ -79,6 +82,8 @@ class GitShields extends Task
{ {
$username = $this->settings->get('username'); $username = $this->settings->get('username');
$this->username = is_string($username) ? $username : ''; $this->username = is_string($username) ? $username : '';
$domain = $this->settings->get('domain');
$this->domain = is_string($domain) ? $domain : 'github.com';
$this->dotaddict = (bool) $this->settings->get('dotaddict'); $this->dotaddict = (bool) $this->settings->get('dotaddict');
return true; return true;
@ -94,6 +99,7 @@ class GitShields extends Task
if (!empty($_POST['save']) && !empty($_POST['username'])) { if (!empty($_POST['save']) && !empty($_POST['username'])) {
$this->settings->set([ $this->settings->set([
'username' => (string) $_POST['username'], 'username' => (string) $_POST['username'],
'domain' => (string) $_POST['domain'],
'dotaddict' => !empty($_POST['dotaddict']), 'dotaddict' => !empty($_POST['dotaddict']),
]); ]);
$this->redirect($url); $this->redirect($url);
@ -101,6 +107,12 @@ class GitShields extends Task
return (new Div())->items([ return (new Div())->items([
(new Fieldset())->class('fieldset')->legend((new Legend(__('Contents'))))->fields([ (new Fieldset())->class('fieldset')->legend((new Legend(__('Contents'))))->fields([
// domain
(new Para())->items([
(new Label(__('Your Github repository domain:'), Label::OUTSIDE_LABEL_BEFORE))->for('domain'),
(new Input('domain'))->size(65)->maxlenght(255)->value($this->domain),
]),
(new Note())->text(__('By default this is github.com or you can specify a custom gitea domain'))->class('form-note'),
// username // username
(new Para())->items([ (new Para())->items([
(new Label(__('Your Github user name:'), Label::OUTSIDE_LABEL_BEFORE))->for('username'), (new Label(__('Your Github user name:'), Label::OUTSIDE_LABEL_BEFORE))->for('username'),
@ -147,6 +159,7 @@ class GitShields extends Task
} }
$blocs[$k] = trim(str_replace( $blocs[$k] = trim(str_replace(
[ [
'%domain%',
'%username%', '%username%',
'%module%', '%module%',
'%dotclear%', '%dotclear%',
@ -154,6 +167,7 @@ class GitShields extends Task
"\r\n", "\n", "\r\n", "\n",
], ],
[ [
$this->domain,
$this->username, $this->username,
$this->module->getId(), $this->module->getId(),
$dotclear = $this->getDotclearVersion(), $dotclear = $this->getDotclearVersion(),