Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parseGitURI is not working for repositories in sub directory #148

Open
alirezavalizade opened this issue Feb 5, 2024 · 1 comment
Open

Comments

@alirezavalizade
Copy link

alirezavalizade commented Feb 5, 2024

Hi :) Let's say we have a repository name within a directory in GitLab, such as xxx/dir/website-1#master. The regular expression you are using here is not working for this type of repository name.

/^(?<repo>[\w.-]+\/[\w.-]+)(?<subdir>[^#]+)?(?<ref>#[\w./-]+)?/;

resulting:
"url": "https://git.xxx.com/xxx/dir/tree/master/website-1",

and should be
"url": "https://git.xxx.com/xxx/dir/website-1/tree/master/website-1-master.tar.bz"

@JvanderHeide
Copy link

JvanderHeide commented May 16, 2024

We're using groups in gitlab and are experiencing the same issue. I've been able to (albeit nasty, by copying some code) to provide for our own specific use case, it may be crude but it works for now. The original idea I had was to call the provided gitlab TemplateProvider and override properties on the object where necessary, but as they are not exported I had to resort to copying it. I've also tried naming it as an other provider entirely but that didn't seem to get picked up.

/**
 * Handles the parsing of gitlab repo's with groups,
 * does not work with nested branches in return as it assumes any slash after # is going to be the sub dir
 * 
 * Copied from built-in giget gitlab TemplateProvider
 * @see node_modules/giget/dist/index.cjs
 * @see node_modules/giget/dist/index.mjs
 * */
const groupedGitlab: TemplateProvider = async (input, options) => {
    const gitlab = process.env.GIGET_GITLAB_URL || "https://gitlab.com";

    const [repo, refWithPath = 'main'] = input.split('#');
    const [ref, subDir = '/'] = refWithPath.split('/');

    return {
        name: repo.replace("/", "-"),
        version: ref,
        subdir: subDir,
        headers: {
            authorization: options.auth ? `Bearer ${options.auth}` : void 0,
            // https://gitlab.com/gitlab-org/gitlab/-/commit/50c11f278d18fe1f3fb12eb595067216bb58ade2
            "sec-fetch-mode": "same-origin"
        },
        url: `${gitlab}/${repo}/tree/${ref}${subDir}`,
        tar: `${gitlab}/${repo}/-/archive/${ref}.tar.gz`
    };
};
import {groupedGitlab} from "./template-providers/grouped-gitlab";

export default defineNuxtConfig({
    extends: [
        ['gitlab:technology/nuxt-layers/example-layer', {
            giget: {
                providers: {
                    gitlab: groupedGitlab
                },
            }
        }]
    ],
});

Did not properly test with subDir and refs, just wanted to share with you and others, what I came up with whilst trying to work around the same issue.

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

No branches or pull requests

2 participants