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 {
},
computed: {
...mapState(['composerHelpPath']),
...mapGetters(['composerRegistryInclude', 'composerPackageInclude']),
...mapGetters(['composerRegistryInclude', 'composerPackageInclude', 'groupExists']),
},
i18n: {
registryInclude: s__('PackageRegistry|composer.json registry include'),
registryInclude: s__('PackageRegistry|Add composer registry'),
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'),
infoLine: s__(
'PackageRegistry|For more information on Composer packages in GitLab, %{linkStart}see the documentation.%{linkEnd}',
......@@ -32,31 +32,33 @@ export default {
<template>
<div>
<h3 class="gl-font-lg">{{ __('Installation') }}</h3>
<div v-if="groupExists">
<h3 class="gl-font-lg">{{ __('Installation') }}</h3>
<code-instruction
:label="$options.i18n.registryInclude"
:instruction="composerRegistryInclude"
:copy-text="$options.i18n.copyRegistryInclude"
:tracking-action="$options.trackingActions.COPY_COMPOSER_REGISTRY_INCLUDE_COMMAND"
:tracking-label="$options.TrackingLabels.CODE_INSTRUCTION"
data-testid="registry-include"
/>
<code-instruction
:label="$options.i18n.registryInclude"
:instruction="composerRegistryInclude"
:copy-text="$options.i18n.copyRegistryInclude"
:tracking-action="$options.trackingActions.COPY_COMPOSER_REGISTRY_INCLUDE_COMMAND"
:tracking-label="$options.TrackingLabels.CODE_INSTRUCTION"
data-testid="registry-include"
/>
<code-instruction
:label="$options.i18n.packageInclude"
:instruction="composerPackageInclude"
:copy-text="$options.i18n.copyPackageInclude"
:tracking-action="$options.trackingActions.COPY_COMPOSER_PACKAGE_INCLUDE_COMMAND"
:tracking-label="$options.TrackingLabels.CODE_INSTRUCTION"
data-testid="package-include"
/>
<span data-testid="help-text">
<gl-sprintf :message="$options.i18n.infoLine">
<template #link="{ content }">
<gl-link :href="composerHelpPath" target="_blank">{{ content }}</gl-link>
</template>
</gl-sprintf>
</span>
<code-instruction
:label="$options.i18n.packageInclude"
:instruction="composerPackageInclude"
:copy-text="$options.i18n.copyPackageInclude"
:tracking-action="$options.trackingActions.COPY_COMPOSER_PACKAGE_INCLUDE_COMMAND"
:tracking-label="$options.TrackingLabels.CODE_INSTRUCTION"
data-testid="package-include"
/>
<span data-testid="help-text">
<gl-sprintf :message="$options.i18n.infoLine">
<template #link="{ content }">
<gl-link :href="composerHelpPath" target="_blank">{{ content }}</gl-link>
</template>
</gl-sprintf>
</span>
</div>
</div>
</template>
......@@ -102,11 +102,12 @@ repository = ${pypiSetupPath}
username = __token__
password = <your personal access token>`;
export const composerRegistryInclude = ({ composerPath }) => {
const base = { type: 'composer', url: composerPath };
return JSON.stringify(base);
};
export const composerPackageInclude = ({ packageEntity }) => {
const base = { [packageEntity.name]: packageEntity.version };
return JSON.stringify(base);
};
export const composerRegistryInclude = ({ composerPath, composerConfigRepositoryName }) =>
// eslint-disable-next-line @gitlab/require-i18n-strings
`composer config repositories.${composerConfigRepositoryName} '{"type": "composer", "url": "${composerPath}"}'`;
export const composerPackageInclude = ({ packageEntity }) =>
// eslint-disable-next-line @gitlab/require-i18n-strings
`composer req ${[packageEntity.name]}:${packageEntity.version}`;
export const groupExists = ({ groupListUrl }) => groupListUrl.length > 0;
......@@ -34,6 +34,10 @@ module PackagesHelper
expose_url(api_v4_group___packages_composer_packages_path(id: group_id, format: '.json'))
end
def composer_config_repository_name(group_id)
"#{Gitlab.config.gitlab.host}/#{group_id}"
end
def packages_list_data(type, resource)
{
resource_id: resource.id,
......
......@@ -24,4 +24,5 @@
composer_help_path: help_page_path('user/packages/composer_repository/index'),
project_name: @project.name,
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 ""
msgid "PackageRegistry|Add NuGet Source"
msgstr ""
msgid "PackageRegistry|Add composer registry"
msgstr ""
msgid "PackageRegistry|App group: %{group}"
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."
msgstr ""
msgid "PackageRegistry|Install package version"
msgstr ""
msgid "PackageRegistry|Learn how to %{noPackagesLinkStart}publish and share your packages%{noPackagesLinkEnd} with GitLab."
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."
msgstr ""
msgid "PackageRegistry|composer.json registry include"
msgstr ""
msgid "PackageRegistry|composer.json require package include"
msgstr ""
msgid "PackageRegistry|npm command"
msgstr ""
......
......@@ -15,15 +15,18 @@ describe('ComposerInstallation', () => {
const composerRegistryIncludeStr = 'foo/registry';
const composerPackageIncludeStr = 'foo/package';
const groupExists = true;
const store = new Vuex.Store({
state: {
packageEntity,
composerHelpPath,
groupExists,
},
getters: {
composerRegistryInclude: () => composerRegistryIncludeStr,
composerPackageInclude: () => composerPackageIncludeStr,
groupExists: () => groupExists,
},
});
......@@ -62,7 +65,7 @@ describe('ComposerInstallation', () => {
});
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', () => {
});
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', () => {
......
......@@ -15,6 +15,7 @@ import {
pypiSetupCommand,
composerRegistryInclude,
composerPackageInclude,
groupExists,
} from '~/packages/details/store/getters';
import {
conanPackage,
......@@ -68,10 +69,11 @@ describe('Getters PackageDetails Store', () => {
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 composerRegistryIncludeStr = '{"type":"composer","url":"foo"}';
const composerPackageIncludeStr = JSON.stringify({
[packageWithoutBuildInfo.name]: packageWithoutBuildInfo.version,
});
const composerRegistryIncludeStr =
'composer config repositories.gitlab.com/123 \'{"type": "composer", "url": "foo"}\'';
const composerPackageIncludeStr = `composer req ${[packageWithoutBuildInfo.name]}:${
packageWithoutBuildInfo.version
}`;
describe('packagePipeline', () => {
it('should return the pipeline info when pipeline exists', () => {
......@@ -221,7 +223,7 @@ describe('Getters PackageDetails Store', () => {
describe('composer string getters', () => {
it('gets the correct composerRegistryInclude command', () => {
setupState({ composerPath: 'foo' });
setupState({ composerPath: 'foo', composerConfigRepositoryName: 'gitlab.com/123' });
expect(composerRegistryInclude(state)).toBe(composerRegistryIncludeStr);
});
......@@ -232,4 +234,18 @@ describe('Getters PackageDetails Store', () => {
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
expect(url).to eq("#{base_url}group/1/-/packages/composer/packages.json")
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
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