如何配置私有Bitbucket存储库,以便我可以在composer.json中包含私有包?



我在Bitbucket.org有一个私有Git存储库。它由一个准备用作composerpackageLaravel项目组成。我不想发布它,我只是希望能够通过将其包含在composer.json中来使用它,从而在我的其他Laravel项目中使用它。我在谷歌上搜索了很多关于堆栈溢出的教程和问题/答案,但我仍然无法做到这一点。这是我composer.json文件中应该相关的部分:

"require": {
"php": ">=5.6.4",
"myprovider/mypackage": "*",
"laravel/framework": "5.4.*",
"laravel/tinker": "~1.0"
},
"repositories": {
"myrepository": {
"type": "vcs",
"url": "https://bitbucket.org/me/myrepository/"
}
},

我尝试了composer require myprovider/mypackage:*,但后来我Could not fetch https://api.bitbucket.org/2.0/repositories/me/myrepository?fields=-project%2C-owner, please create a bitbucket OAuth token to access private repos出现错误。由于我之前实际上创建了OAuth令牌,因此我粘贴了所需的Consumer KeyConsumer Secret但是后来我得到了这个:

Invalid OAuth consumer provided.
This can have two reasons:
1. You are authenticating with a bitbucket username/password combination
2. You are using an OAuth consumer, but didn't configure a (dummy) callback url
Installation failed, reverting ./composer.json to its original content.
[ComposerDownloaderTransportException]
The "?pagelen=100&fields=values.name%2Cvalues.target.hash%2Cnext&sort=-target.date" 
file could not be downloaded: failed to open stream: Resource temporarily unavailable

我是Bitbucket新手,我怎么知道我是否正确配置了所有内容?

一步一步的配置会很棒,我在网上发现的都不适合我的情况。

以下答案是我按照这篇博文的说明并看到它工作后的个人笔记。

非常感谢gizmola的博客文章和gview的评论指向它。

假设对于您的项目my-name/my-project您希望将私有包myprovider/my-private-package托管在 bitbucket 上。

  • 登录位桶
  • bitbucket settings>access management>oauth
  • 添加 OAuth 使用者

    • 姓名:作曲家
    • 回调:(必填但未使用(http://example.com
    • 勾选:这是私人消费者
    • 勾号:permissions>repositories>read
  • composer oauth consumer / user for private repos获取密钥和机密

  • 打开/创建~/.composer/auth.json并确保它有替换xxxxxyyyyy的位置

    {
    "bitbucket-oauth": {
    "bitbucket.org": {
    "consumer-key": "xxxxx",
    "consumer-secret": "yyyyyy"
    }
    }
    }
    
  • 将包添加到 composer.json

    {
    "name" : "my-name/my-project",
    "description" : "my project",
    "repositories": [
    {
    "type": "git",
    "url":  "https://bitbucket.org/myprovider/my-private-package.git"
    }
    ],
    "require": {
    "myprovider/my-private-package": "*"
    }
    }
    

请记住,如果私有包的 composer.json 没有minimum-stability设置(例如 todev(,它将不起作用。

作曲家.json 的示例myprovider/my-private-package

{
"name": "myprovider/my-private-package",
"description": "my private package",
"keywords": ["private package", "private", "package"],
"type": "package",
"version": "1.0.0",
"minimum-stability": "dev",
"license": "MIT",
"authors": [
{
"name": "John Doe",
"email": "john.doe@example.com"
}
],
"autoload": {"psr-0": {"": "src"}},
"require-dev": {
"behat/behat": "^3.4"
}
}

相关内容

  • 没有找到相关文章

最新更新