简体   繁体   English

Composer 需要来自 gitlab 的私有存储库 ssh 被忽略

[英]Composer require private repository from gitlab ssh ignored

I'm trying to pull a private repository from gitlab with composer without any success.我正在尝试使用 composer 从 gitlab 中提取一个私有存储库,但没有任何成功。

This is what I have in my composer.json file under repositories:这是我在存储库下的 composer.json 文件中的内容:

"repositories": [
  {
     "type": "vcs",
     "url": "git@gitlab.com:the-vendor/dashboard-api.git"
  }
]

When I clone the project like this: git@gitlab.com:the-vendor/dashboard-api.git manually, everything works fine.当我像这样手动克隆项目时: git@gitlab.com:the-vendor/dashboard-api.git ,一切正常。

Now when I require the project like so:现在,当我需要这样的项目时:

"require": {
  "the-vendor/dashboard": "dev-orchestrate"
}

I also tried: "dev-main", "dev-main@dev", "dev-orchestrate@dev".我也试过:“dev-main”、“dev-main@dev”、“dev-orchestrate@dev”。

And run: composer update the-vendor/dashboard I get the following error:并运行: composer update the-vendor/dashboard我得到以下错误:

Failed to download the-vendor/dashboard-api:The "https://gitlab.com/api/v4/projects/joij%2Fdashboard-api" file could not be downloaded (HTTP/2 404 ):
{"message":"404 Project Not Found"}
Your credentials are required to fetch private repository metadata (git@gitlab.com:the-vendor/dashboard-api.git)
A token will be created and stored in "/root/.composer/auth.json", your password will never be stored
To revoke access to this token you can visit https://gitlab.com/-/profile/personal_access_tokens
Username:

Installation failed, reverting ./composer.json and ./composer.lock to their original content.

I'm not sure what to make of this.我不知道该怎么做。 Composer should be able to clone the project through ssh. Composer 应该能够通过 ssh 克隆项目。 But instead I get that vague 404 and then I have to give my username and password.但相反,我得到了那个模糊的 404,然后我必须提供我的用户名和密码。

I also tried this:我也试过这个:

"repositories": [
  {
     "type": "git",
     "url": "git@gitlab.com:the-vendor/dashboard-api.git"
  }
]

But then it behaves as if there is no "repositories" in the composer json at all, and I get this error:但随后它的行为就好像在作曲家 json 中根本没有“存储库”,我得到了这个错误:

Problem 1
    - Root composer.json requires the-vendor/dashboard, it could not be found in any version, there may be a typo in the package name.

Potential causes:
 - A typo in the package name
 - The package is not available in a stable-enough version according to your minimum-stability setting
   see <https://getcomposer.org/doc/04-schema.md#minimum-stability> for more details.
 - It's a private package and you forgot to add a custom repository to find it

Read <https://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.

This is the composer.json of the dashboard-api:这是dashboard-api的composer.json:

{
    "name": "the-vendor/dashboard",
    "type": "project",
    "description": "TheVendor Dashboards",
    "keywords": ["framework", "laravel"],
    "license": "proprietary",
    "require": {
        "php": "^8.1",
        "elasticsearch/elasticsearch": "v7.17.0",
        "guzzlehttp/guzzle": "^7.2",
        "laravel/framework": "^9.2",
        "laravel/sanctum": "^2.14.1",
        "laravel/tinker": "^2.7",
        "ext-pdo": "*"
    },
    "require-dev": {
        "fakerphp/faker": "^1.9.1",
        "laravel/sail": "^1.0.1",
        "mockery/mockery": "^1.4.4",
        "nunomaduro/collision": "^6.1",
        "phpunit/phpunit": "^9.5.10",
        "phpspec/prophecy": "1.15.0",
        "spatie/laravel-ignition": "^1.0"
    },
    "autoload": {
        "psr-4": {
            "TheVendor\\Dashboard\\": "app/",
            "Database\\Factories\\": "database/factories/",
            "Database\\Seeders\\": "database/seeders/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-update-cmd": [
            "@php artisan vendor:publish --tag=laravel-assets --ansi --force"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    },
    "extra": {
        "laravel": {
            "providers": [
                "TheVendor\\Dashboard\\Providers\\AppServiceProvider",
                "TheVendor\\Dashboard\\Providers\\ESClientServiceProvider",
                "TheVendor\\Dashboard\\Providers\\ESCreateIndexesServiceProvider"
            ],
            "dont-discover": []
        }
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "minimum-stability": "dev",
    "prefer-stable": true
}

I wonder if anyone knows what I'm missing.我想知道是否有人知道我错过了什么。

Alright!好吧! I found the problem.我发现了问题。 There is no need to go for an auth.json with an API Token.无需使用带有 API 令牌的 auth.json。 This is where I went wrong:这是我出错的地方:

The main branch had a different package name!主分支有不同的包名! The branch I was trying to pull had the right one, but if the main composer.json has a different package name you get this error:我试图拉的分支是正确的,但如果主 composer.json 有不同的包名,你会得到这个错误:

Root composer.json requires the-vendor/dashboard, it could not be found in any version, there may be a typo in the package name.

Once you have that, and require the package like this:一旦你有了它,并且需要这样的包:

"require": [
    "the-vendor/dashboard": "dev-orchestrate"
]

With this in the root of composer.json在 composer.json 的根目录中

"repositories": [
   {
       "type": "git",
       "url": "git@gitlab.com:the-vendor/dashboard-api.git"
   }
]

It will simply use ssh to clone the private repository它将简单地使用 ssh 克隆私有存储库

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM