code.gitea.io/gitea@v1.22.3/docs/content/usage/packages/composer.en-us.md (about)

     1  ---
     2  date: "2021-07-20T00:00:00+00:00"
     3  title: "Composer Package Registry"
     4  slug: "composer"
     5  sidebar_position: 10
     6  draft: false
     7  toc: false
     8  menu:
     9    sidebar:
    10      parent: "packages"
    11      name: "Composer"
    12      sidebar_position: 10
    13      identifier: "composer"
    14  ---
    15  
    16  # Composer Package Registry
    17  
    18  Publish [Composer](https://getcomposer.org/) packages for your user or organization.
    19  
    20  ## Requirements
    21  
    22  To work with the Composer package registry, you can use [Composer](https://getcomposer.org/download/) to consume and a HTTP upload client like `curl` to publish packages.
    23  
    24  ## Publish a package
    25  
    26  To publish a Composer package perform a HTTP PUT operation with the package content in the request body.
    27  The package content must be the zipped PHP project with the `composer.json` file.
    28  
    29  You cannot publish a package if a package of the same name and version already exists. You must delete the existing package first.
    30  
    31  ```
    32  PUT https://gitea.example.com/api/packages/{owner}/composer
    33  ```
    34  
    35  | Parameter  | Description |
    36  | ---------- | ----------- |
    37  | `owner`    | The owner of the package. |
    38  
    39  If the `composer.json` file does not contain a `version` property, you must provide it as a query parameter:
    40  
    41  ```
    42  PUT https://gitea.example.com/api/packages/{owner}/composer?version={x.y.z}
    43  ```
    44  
    45  Example request using HTTP Basic authentication:
    46  
    47  ```shell
    48  curl --user your_username:your_password_or_token \
    49       --upload-file path/to/project.zip \
    50       https://gitea.example.com/api/packages/testuser/composer
    51  ```
    52  
    53  Or specify the package version as query parameter:
    54  
    55  ```shell
    56  curl --user your_username:your_password_or_token \
    57       --upload-file path/to/project.zip \
    58       https://gitea.example.com/api/packages/testuser/composer?version=1.0.3
    59  ```
    60  
    61  If you are using 2FA or OAuth use a [personal access token](development/api-usage.md#authentication) instead of the password.
    62  
    63  The server responds with the following HTTP Status codes.
    64  
    65  | HTTP Status Code  | Meaning |
    66  | ----------------- | ------- |
    67  | `201 Created`     | The package has been published. |
    68  | `400 Bad Request` | The package is invalid. |
    69  | `409 Conflict`    | A package file with the same combination of parameters exists already. |
    70  
    71  ## Configuring the package registry
    72  
    73  To register the package registry you need to add it to the Composer `config.json` file (which can usually be found under `<user-home-dir>/.composer/config.json`):
    74  
    75  ```json
    76  {
    77    "repositories": [{
    78        "type": "composer",
    79        "url": "https://gitea.example.com/api/packages/{owner}/composer"
    80     }
    81    ]
    82  }
    83  ```
    84  
    85  To access the package registry using credentials, you must specify them in the `auth.json` file as follows:
    86  
    87  ```json
    88  {
    89    "http-basic": {
    90      "gitea.example.com": {
    91        "username": "{username}",
    92        "password": "{password}"
    93      }
    94    }
    95  }
    96  ```
    97  
    98  | Parameter  | Description |
    99  | ---------- | ----------- |
   100  | `owner`    | The owner of the package. |
   101  | `username` | Your Gitea username. |
   102  | `password` | Your Gitea password or a personal access token. |
   103  
   104  ## Install a package
   105  
   106  To install a package from the package registry, execute the following command:
   107  
   108  ```shell
   109  composer require {package_name}
   110  ```
   111  
   112  Optional you can specify the package version:
   113  
   114  ```shell
   115  composer require {package_name}:{package_version}
   116  ```
   117  
   118  | Parameter         | Description |
   119  | ----------------- | ----------- |
   120  | `package_name`    | The package name. |
   121  | `package_version` | The package version. |