使用私有 Bitbucket Mercurial 存储库配置 composer.jsonMercurial、Bitbucket、json、composer

2023-09-06 16:55:44 作者:落魄

我的项目使用我自己的库,该库位于位于 bitbucket.org 上的私有 Mercurial 存储库中.该库没有配置 composer.json.

My project uses my own library which is in the private Mercurial repository placed on bitbucket.org. That library has no composer.json configured.

我尝试将该库作为我项目的依赖项.

I try to make that library as a dependency to my project.

首先我给composer.json写了以下字符串:

Firstly I wrote to composer.json the following strings:

{
"require": {
    "php": ">=5.4",
    "myname/mylibname": "dev"
},

"repositories":[
    {
        "type": "hg",
        "url" : "https://bitbucket.org/myname/mylibname"
    }
]
}

并且运行 composer install 我有一个错误:

And running composer install I've got an error:

[运行时异常]克隆 https://bitbucket.org/myname/mylibname 失败,无法从中读取包abort:需要http授权

[RuntimeException] Failed to clone https://bitbucket.org/myname/mylibname, could not read packages from it abort: http authorization required

比我将 "type": "hg" 更改为 "type": "vcs" 并得到另一个错误:

Than I changed "type": "hg" to "type": "vcs" and got another error:

[ComposerRepositoryInvalidRepositoryException]在 https://***/mylibname 的任何分支或标签中找不到有效的 composer.json,无法从中加载包.

[ComposerRepositoryInvalidRepositoryException] No valid composer.json was found in any branch or tag of https:/***/mylibname, could not load a package from it.

在额外阅读文档后,我在项目的 composer.json 中添加了对我的库的描述,它开始看起来像这样:

After additional reading of documentation I added description of my library to the composer.json of my project, and it began to look so:

{
"require": {
    "php": ">=5.4",
    "myname/mylibname": "dev"
},

"repositories":[

    {
        "type": "vcs",
        "url" : "https://bitbucket.org/myname/mylibname"
    },
    {
        "type":"package",
        "package":{
            "name":"myname/mylibname",
            "version": "dev",
            "source":{
                "type":"vcs",
                "url":"https://bitbucket.org/myname/mylibname",
                "reference":"dev"
            }
        }
    }
]}

同样的错误发生了:

[ComposerRepositoryInvalidRepositoryException]在 https://***/mylibname 的任何分支或标签中找不到有效的 composer.json,无法从中加载包.

源代码存放托管仓库bitbucket简单介绍

[ComposerRepositoryInvalidRepositoryException] No valid composer.json was found in any branch or tag of https:/***/mylibname, could not load a package from it.

我删除了部分:

        {
        "type": "vcs",
        "url" : "https://bitbucket.org/myname/mylibname"
    },

得到一个错误:

[无效参数异常]未知下载器类型:vcs.可用类型:git、svn、hg、perforce、zip、rar、tar、gzip、phar、file.

[InvalidArgumentException] Unknown downloader type: vcs. Available types: git, svn, hg, perforce, zip, rar, tar, gzip, phar, file.

我把 "type": "vcs" 改回 "type": "hg",composer.json 看起来像:

I changed "type": "vcs" back to "type": "hg", composer.json looks like:

{
"require": {
    "php": ">=5.4",
    "myname/mylibname": "dev"
},

"repositories":[
    {
        "type":"package",
        "package":{
            "name":"myname/mylibname",
            "version": "dev",
            "source":{
                "type":"hg",
                "url":"https://bitbucket.org/myname/mylibname",
                "reference":"dev"
            }
        }
    }
]}

还有一个错误:

[运行时异常]未能执行 hg clone 'https://***/mylibname' '/path/to/myproject'abort:需要http授权

[RuntimeException] Failed to execute hg clone 'https:/***/mylibname' '/path/to/myproject' abort: http authorization required

除了composer.json之外,我的auth.json的结构是:

The structure of my auth.json, which lies besides of composer.json is:

{
"http-basic": {
    "bitbucket.org": {
        "username": "myusername",
        "password": "mypassword"
    }
}
}

推荐答案

似乎 bitbucket-oauth 方法在 composer 1.1 的当前状态下是错误的.这意味着您必须在客户端上设置 SSH 密钥,或者如果您像我一样由于部署服务器而无法设置密钥,则必须使用基本身份验证.

Seems like bitbucket-oauth method is buggy in the current state as of 1.1 of composer. This means that either you must have setup the SSH key on the client or if you are like me and cant setup keys because of deployment server, you will have to use basic auth.

我得到这个工作的唯一方法是:

The only way I got this working was:

~/.composer/auth.json

{
    "http-basic": {
        "bitbucket.org": {
            "username": "bitbucketUsername",
            "password": "PasswordToBitbucket"
        }
    }
}

composer.json

"repositories": [
        {
            "url": "https://username@bitbucket.org/username/my-package.git",
            "type": "git"
        }

],
"require": {
        "username/my-package": "dev-master"
},