4

我在 github 上建立了一个satis存储库,用于跨项目共享一些公司内部包。

现在,当我尝试“依赖”新存储库时,我尝试了以下操作:

"repositories": [ {
    "type": "composer",
    "url": "https://raw.githubusercontent.com/[organisation]/satis/master/web/packages.json?token=[token-copied-from-url]"
} ]

它的工作原理足以让作曲家找到 package.json,但是,它失败了:

[Composer\Downloader\TransportException]
  The "https://raw.githubusercontent.com/[organization]/satis/master/web/packages.json?token=[token-copied-from-url]/include/all$[some-json-file].json" file could not be downloaded (HTTP/1.1 404 Not Found)

这并不奇怪,因为 ?token 部分似乎生成了无效的 url。

我可以通过手动将包含文件的内容直接移动到 packages.json 来解决这个问题,但这并不理想,特别是如果 satis 决定生成多个文件。

我认为这会导致的另一个问题是我对令牌的有效性知之甚少。也许它的寿命不长,然后需要定期重新生成 satis。

有没有办法将我的 satis 存储库托管为“只是”一个 github 存储库?

4

2 回答 2

2

您可以将静态 Satis 存储库存储在私有 GitHub 存储库中,然后使用 GitHub 的raw.githubusercontent.com域通过 HTTPS 提供服务。稍微麻烦的部分是确保作曲家正确地对 GitHub 存储库进行身份验证。

将 Satis 存储库推送到 GitHub

生成您的 Satis 存储库并将其推送到您的私有 GitHub 存储库,假设https://github.com/your-org/your-satis-repooutput/目录中。

准备项目的 composer.json 文件

在您项目的 composer.json 文件中,将您的 Satis 存储库添加到“存储库”部分:

{
    "type": "composer",
    "url": "https://raw.githubusercontent.com/your-org/your-satis-repo/master/output"
}

设置 HTTP 基本身份验证

最后,要使作曲家通过 HTTP 基本身份验证对raw.githubusercontent.com您进行身份验证,您需要在本地作曲家的 auth.json 中的“http-basic”部分添加一个新条目:

{
    "http-basic": {
        "raw.githubusercontent.com": {
            "username": "GITHUB_USERNAME",
            "password": "GITHUB_TOKEN"
        }
    }
}

注意事项

  • 我们发现它raw.githubusercontent.com已被缓存,因此可能需要几分钟才能看到对您的 Satis 存储库的更改。
于 2018-01-30T18:01:56.410 回答
1

初步测试表明可以做到。

我认为您需要从存储库 URL 中删除 packages.json 并且我怀疑 ?token 参数。理论上,您可以通过标头传递令牌:

https://developer.github.com/v3/#authentication

但是,我还没有对此进行测试。

您可以在此处查看未经身份验证的工作测试:

尝试一下:

git clone git@github.com:markchalloner/satishostcomposer.git
cd satishostcomposer
composer install

应该安装 vendor/markchalloner/satishostdemo

示例 satis.json:

{
    "name": "Satis Host",
    "homepage": "https://raw.githubusercontent.com/markchalloner/satishost/master/web/",
    "archive": {
        "directory": "dist",
        "format": "tar",
        "prefix-url": "https://raw.githubusercontent.com/markchalloner/satishost/master/web/",
        "skip-dev": true
    },
    "repositories": [
        {
            "_comment": "Demo packages",
            "type": "package",
            "package": {
                "name": "markchalloner/satishostdemo",
                "version": "0.1.0",
                "dist": {
                    "type": "zip",
                    "url": "dist/demo.zip"
                }
            }
        }
    ],
    "require-all": true
}

示例 composer.json(在您的项目中):

{
    "repositories": [
        {
            "type": "composer",
            "url": "https://raw.githubusercontent.com/markchalloner/satishost/master/web",
            "options":  {
                "http": {
                    "header": [
                        "API-TOKEN: YOUR-API-TOKEN"
                    ]
                }
            }
        }
    ],
    "require": {
        "markchalloner/satishostdemo": "0.1.0"
    },
    "minimum-stability": "dev"
}

谢谢

于 2015-06-09T12:06:29.583 回答