Commit fecbfde4 authored by Ochorocho's avatar Ochorocho

Use actual composer command

... as example for package include and `composer config repositories` command for registry include
parent 826711fa
...@@ -14,12 +14,12 @@ export default { ...@@ -14,12 +14,12 @@ export default {
}, },
computed: { computed: {
...mapState(['composerHelpPath']), ...mapState(['composerHelpPath']),
...mapGetters(['composerRegistryInclude', 'composerPackageInclude']), ...mapGetters(['composerRegistryInclude', 'composerPackageInclude', 'groupExists']),
}, },
i18n: { i18n: {
registryInclude: s__('PackageRegistry|composer.json registry include'), registryInclude: s__('PackageRegistry|Add composer registry'),
copyRegistryInclude: s__('PackageRegistry|Copy registry include'), copyRegistryInclude: s__('PackageRegistry|Copy registry include'),
packageInclude: s__('PackageRegistry|composer.json require package include'), packageInclude: s__('PackageRegistry|Install package version'),
copyPackageInclude: s__('PackageRegistry|Copy require package include'), copyPackageInclude: s__('PackageRegistry|Copy require package include'),
infoLine: s__( infoLine: s__(
'PackageRegistry|For more information on Composer packages in GitLab, %{linkStart}see the documentation.%{linkEnd}', 'PackageRegistry|For more information on Composer packages in GitLab, %{linkStart}see the documentation.%{linkEnd}',
...@@ -32,31 +32,33 @@ export default { ...@@ -32,31 +32,33 @@ export default {
<template> <template>
<div> <div>
<h3 class="gl-font-lg">{{ __('Installation') }}</h3> <div v-if="groupExists">
<h3 class="gl-font-lg">{{ __('Installation') }}</h3>
<code-instruction <code-instruction
:label="$options.i18n.registryInclude" :label="$options.i18n.registryInclude"
:instruction="composerRegistryInclude" :instruction="composerRegistryInclude"
:copy-text="$options.i18n.copyRegistryInclude" :copy-text="$options.i18n.copyRegistryInclude"
:tracking-action="$options.trackingActions.COPY_COMPOSER_REGISTRY_INCLUDE_COMMAND" :tracking-action="$options.trackingActions.COPY_COMPOSER_REGISTRY_INCLUDE_COMMAND"
:tracking-label="$options.TrackingLabels.CODE_INSTRUCTION" :tracking-label="$options.TrackingLabels.CODE_INSTRUCTION"
data-testid="registry-include" data-testid="registry-include"
/> />
<code-instruction <code-instruction
:label="$options.i18n.packageInclude" :label="$options.i18n.packageInclude"
:instruction="composerPackageInclude" :instruction="composerPackageInclude"
:copy-text="$options.i18n.copyPackageInclude" :copy-text="$options.i18n.copyPackageInclude"
:tracking-action="$options.trackingActions.COPY_COMPOSER_PACKAGE_INCLUDE_COMMAND" :tracking-action="$options.trackingActions.COPY_COMPOSER_PACKAGE_INCLUDE_COMMAND"
:tracking-label="$options.TrackingLabels.CODE_INSTRUCTION" :tracking-label="$options.TrackingLabels.CODE_INSTRUCTION"
data-testid="package-include" data-testid="package-include"
/> />
<span data-testid="help-text"> <span data-testid="help-text">
<gl-sprintf :message="$options.i18n.infoLine"> <gl-sprintf :message="$options.i18n.infoLine">
<template #link="{ content }"> <template #link="{ content }">
<gl-link :href="composerHelpPath" target="_blank">{{ content }}</gl-link> <gl-link :href="composerHelpPath" target="_blank">{{ content }}</gl-link>
</template> </template>
</gl-sprintf> </gl-sprintf>
</span> </span>
</div>
</div> </div>
</template> </template>
...@@ -102,11 +102,12 @@ repository = ${pypiSetupPath} ...@@ -102,11 +102,12 @@ repository = ${pypiSetupPath}
username = __token__ username = __token__
password = <your personal access token>`; password = <your personal access token>`;
export const composerRegistryInclude = ({ composerPath }) => { export const composerRegistryInclude = ({ composerPath, composerConfigRepositoryName }) =>
const base = { type: 'composer', url: composerPath }; // eslint-disable-next-line @gitlab/require-i18n-strings
return JSON.stringify(base); `composer config repositories.${composerConfigRepositoryName} '{"type": "composer", "url": "${composerPath}"}'`;
};
export const composerPackageInclude = ({ packageEntity }) => { export const composerPackageInclude = ({ packageEntity }) =>
const base = { [packageEntity.name]: packageEntity.version }; // eslint-disable-next-line @gitlab/require-i18n-strings
return JSON.stringify(base); `composer req ${[packageEntity.name]}:${packageEntity.version}`;
};
export const groupExists = ({ groupListUrl }) => groupListUrl.length > 0;
...@@ -34,6 +34,10 @@ module PackagesHelper ...@@ -34,6 +34,10 @@ module PackagesHelper
expose_url(api_v4_group___packages_composer_packages_path(id: group_id, format: '.json')) expose_url(api_v4_group___packages_composer_packages_path(id: group_id, format: '.json'))
end end
def composer_config_repository_name(group_id)
"#{Gitlab.config.gitlab.host}/#{group_id}"
end
def packages_list_data(type, resource) def packages_list_data(type, resource)
{ {
resource_id: resource.id, resource_id: resource.id,
......
...@@ -24,4 +24,5 @@ ...@@ -24,4 +24,5 @@
composer_help_path: help_page_path('user/packages/composer_repository/index'), composer_help_path: help_page_path('user/packages/composer_repository/index'),
project_name: @project.name, project_name: @project.name,
project_list_url: project_packages_path(@project), project_list_url: project_packages_path(@project),
group_list_url: @project.group ? group_packages_path(@project.group) : ''} } group_list_url: @project.group ? group_packages_path(@project.group) : '',
composer_config_repository_name: composer_config_repository_name(@project.group&.id)} }
...@@ -18350,6 +18350,9 @@ msgstr "" ...@@ -18350,6 +18350,9 @@ msgstr ""
msgid "PackageRegistry|Add NuGet Source" msgid "PackageRegistry|Add NuGet Source"
msgstr "" msgstr ""
msgid "PackageRegistry|Add composer registry"
msgstr ""
msgid "PackageRegistry|App group: %{group}" msgid "PackageRegistry|App group: %{group}"
msgstr "" msgstr ""
...@@ -18446,6 +18449,9 @@ msgstr "" ...@@ -18446,6 +18449,9 @@ msgstr ""
msgid "PackageRegistry|If you haven't already done so, you will need to add the below to your %{codeStart}pom.xml%{codeEnd} file." msgid "PackageRegistry|If you haven't already done so, you will need to add the below to your %{codeStart}pom.xml%{codeEnd} file."
msgstr "" msgstr ""
msgid "PackageRegistry|Install package version"
msgstr ""
msgid "PackageRegistry|Learn how to %{noPackagesLinkStart}publish and share your packages%{noPackagesLinkEnd} with GitLab." msgid "PackageRegistry|Learn how to %{noPackagesLinkStart}publish and share your packages%{noPackagesLinkEnd} with GitLab."
msgstr "" msgstr ""
...@@ -18536,12 +18542,6 @@ msgstr "" ...@@ -18536,12 +18542,6 @@ msgstr ""
msgid "PackageRegistry|You may also need to setup authentication using an auth token. %{linkStart}See the documentation%{linkEnd} to find out more." msgid "PackageRegistry|You may also need to setup authentication using an auth token. %{linkStart}See the documentation%{linkEnd} to find out more."
msgstr "" msgstr ""
msgid "PackageRegistry|composer.json registry include"
msgstr ""
msgid "PackageRegistry|composer.json require package include"
msgstr ""
msgid "PackageRegistry|npm command" msgid "PackageRegistry|npm command"
msgstr "" msgstr ""
......
...@@ -15,15 +15,18 @@ describe('ComposerInstallation', () => { ...@@ -15,15 +15,18 @@ describe('ComposerInstallation', () => {
const composerRegistryIncludeStr = 'foo/registry'; const composerRegistryIncludeStr = 'foo/registry';
const composerPackageIncludeStr = 'foo/package'; const composerPackageIncludeStr = 'foo/package';
const groupExists = true;
const store = new Vuex.Store({ const store = new Vuex.Store({
state: { state: {
packageEntity, packageEntity,
composerHelpPath, composerHelpPath,
groupExists,
}, },
getters: { getters: {
composerRegistryInclude: () => composerRegistryIncludeStr, composerRegistryInclude: () => composerRegistryIncludeStr,
composerPackageInclude: () => composerPackageIncludeStr, composerPackageInclude: () => composerPackageIncludeStr,
groupExists: () => groupExists,
}, },
}); });
...@@ -62,7 +65,7 @@ describe('ComposerInstallation', () => { ...@@ -62,7 +65,7 @@ describe('ComposerInstallation', () => {
}); });
it('has the correct title', () => { it('has the correct title', () => {
expect(findRegistryInclude().props('label')).toBe('composer.json registry include'); expect(findRegistryInclude().props('label')).toBe('Add composer registry');
}); });
}); });
...@@ -78,7 +81,7 @@ describe('ComposerInstallation', () => { ...@@ -78,7 +81,7 @@ describe('ComposerInstallation', () => {
}); });
it('has the correct title', () => { it('has the correct title', () => {
expect(findPackageInclude().props('label')).toBe('composer.json require package include'); expect(findPackageInclude().props('label')).toBe('Install package version');
}); });
it('has the correct help text', () => { it('has the correct help text', () => {
......
...@@ -15,6 +15,7 @@ import { ...@@ -15,6 +15,7 @@ import {
pypiSetupCommand, pypiSetupCommand,
composerRegistryInclude, composerRegistryInclude,
composerPackageInclude, composerPackageInclude,
groupExists,
} from '~/packages/details/store/getters'; } from '~/packages/details/store/getters';
import { import {
conanPackage, conanPackage,
...@@ -68,10 +69,11 @@ describe('Getters PackageDetails Store', () => { ...@@ -68,10 +69,11 @@ describe('Getters PackageDetails Store', () => {
const nugetSetupCommandStr = `nuget source Add -Name "GitLab" -Source "${registryUrl}" -UserName <your_username> -Password <your_token>`; const nugetSetupCommandStr = `nuget source Add -Name "GitLab" -Source "${registryUrl}" -UserName <your_username> -Password <your_token>`;
const pypiPipCommandStr = `pip install ${pypiPackage.name} --extra-index-url ${registryUrl}`; const pypiPipCommandStr = `pip install ${pypiPackage.name} --extra-index-url ${registryUrl}`;
const composerRegistryIncludeStr = '{"type":"composer","url":"foo"}'; const composerRegistryIncludeStr =
const composerPackageIncludeStr = JSON.stringify({ 'composer config repositories.gitlab.com/123 \'{"type": "composer", "url": "foo"}\'';
[packageWithoutBuildInfo.name]: packageWithoutBuildInfo.version, const composerPackageIncludeStr = `composer req ${[packageWithoutBuildInfo.name]}:${
}); packageWithoutBuildInfo.version
}`;
describe('packagePipeline', () => { describe('packagePipeline', () => {
it('should return the pipeline info when pipeline exists', () => { it('should return the pipeline info when pipeline exists', () => {
...@@ -221,7 +223,7 @@ describe('Getters PackageDetails Store', () => { ...@@ -221,7 +223,7 @@ describe('Getters PackageDetails Store', () => {
describe('composer string getters', () => { describe('composer string getters', () => {
it('gets the correct composerRegistryInclude command', () => { it('gets the correct composerRegistryInclude command', () => {
setupState({ composerPath: 'foo' }); setupState({ composerPath: 'foo', composerConfigRepositoryName: 'gitlab.com/123' });
expect(composerRegistryInclude(state)).toBe(composerRegistryIncludeStr); expect(composerRegistryInclude(state)).toBe(composerRegistryIncludeStr);
}); });
...@@ -232,4 +234,18 @@ describe('Getters PackageDetails Store', () => { ...@@ -232,4 +234,18 @@ describe('Getters PackageDetails Store', () => {
expect(composerPackageInclude(state)).toBe(composerPackageIncludeStr); expect(composerPackageInclude(state)).toBe(composerPackageIncludeStr);
}); });
}); });
describe('check if group', () => {
it('is set', () => {
setupState({ groupListUrl: '/groups/composer/-/packages' });
expect(groupExists(state)).toBe(true);
});
it('is not set', () => {
setupState({ groupListUrl: '' });
expect(groupExists(state)).toBe(false);
});
});
}); });
...@@ -51,4 +51,15 @@ RSpec.describe PackagesHelper do ...@@ -51,4 +51,15 @@ RSpec.describe PackagesHelper do
expect(url).to eq("#{base_url}group/1/-/packages/composer/packages.json") expect(url).to eq("#{base_url}group/1/-/packages/composer/packages.json")
end end
end end
describe 'composer_config_repository_name' do
let(:host) { Gitlab.config.gitlab.host }
let(:group_id) { 1 }
it 'return global unique composer registry id' do
id = helper.composer_config_repository_name(group_id)
expect(id).to eq("#{host}/#{group_id}")
end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment