|
| 1 | +--- |
| 2 | +title: Source Imports | GitHub API |
| 3 | +--- |
| 4 | + |
| 5 | +# Source Imports |
| 6 | + |
| 7 | +{:toc} |
| 8 | + |
| 9 | +{% if page.version != 'dotcom' %} |
| 10 | + |
| 11 | +{{#warning}} |
| 12 | + |
| 13 | +This API is not currently available on GitHub Enterprise. |
| 14 | + |
| 15 | +{{/warning}} |
| 16 | + |
| 17 | +{% endif %} |
| 18 | + |
| 19 | +{{#tip}} |
| 20 | + |
| 21 | + The source import APIs are currently in public preview. During this period, the APIs may change in a backwards-incompatible way. To access the API during the preview period, you must provide a custom [media type](/v3/media) in the `Accept` header: |
| 22 | + |
| 23 | + application/vnd.github.barred-rock-preview |
| 24 | + |
| 25 | +{{/tip}} |
| 26 | + |
| 27 | +The Source Import API lets you start an import from a Git, Subversion, Mercurial, or Team Foundation Server source repository. This is the same functionality as [the GitHub Importer](https://import.github.com/). |
| 28 | + |
| 29 | +A typical source import would [start the import](#start-an-import) and then (optionally) [update the authors](#map-a-commit-author). A more detailed example can be seen in this diagram: |
| 30 | + |
| 31 | +``` |
| 32 | ++---------+ +--------+ +---------------------+ |
| 33 | +| Tooling | | GitHub | | Original Repository | |
| 34 | ++---------+ +--------+ +---------------------+ |
| 35 | + | | | |
| 36 | + | Start import | | |
| 37 | + |----------------------------->| | |
| 38 | + | | | |
| 39 | + | | Download source data | |
| 40 | + | |--------------------------------------------->| |
| 41 | + | | Begin streaming data | |
| 42 | + | |<---------------------------------------------| |
| 43 | + | | | |
| 44 | + | Get import progress | | |
| 45 | + |----------------------------->| | |
| 46 | + | "status": "importing" | | |
| 47 | + |<-----------------------------| | |
| 48 | + | | | |
| 49 | + | Get commit authors | | |
| 50 | + |----------------------------->| | |
| 51 | + | | | |
| 52 | + | Map a commit author | | |
| 53 | + |----------------------------->| | |
| 54 | + | | | |
| 55 | + | | | |
| 56 | + | | Finish streaming data | |
| 57 | + | |<---------------------------------------------| |
| 58 | + | | | |
| 59 | + | | Rewrite commits with mapped authors | |
| 60 | + | |------+ | |
| 61 | + | | | | |
| 62 | + | |<-----+ | |
| 63 | + | | | |
| 64 | + | | Update repository on GitHub | |
| 65 | + | |------+ | |
| 66 | + | | | | |
| 67 | + | |<-----+ | |
| 68 | + | | | |
| 69 | + | Map a commit author | | |
| 70 | + |----------------------------->| | |
| 71 | + | | Rewrite commits with mapped authors | |
| 72 | + | |------+ | |
| 73 | + | | | | |
| 74 | + | |<-----+ | |
| 75 | + | | | |
| 76 | + | | Update repository on GitHub | |
| 77 | + | |------+ | |
| 78 | + | | | | |
| 79 | + | |<-----+ | |
| 80 | + | | | |
| 81 | + | Get import progress | | |
| 82 | + |----------------------------->| | |
| 83 | + | "status": "complete" | | |
| 84 | + |<-----------------------------| | |
| 85 | + | | | |
| 86 | + | | | |
| 87 | +``` |
| 88 | + |
| 89 | +## Start an import |
| 90 | + |
| 91 | +Start a source import to a GitHub repository using GitHub Importer. |
| 92 | + |
| 93 | + PUT /repos/:owner/:repo/import |
| 94 | + |
| 95 | +### Parameters |
| 96 | + |
| 97 | +Name | Type | Description |
| 98 | +-----|------|-------------- |
| 99 | +`vcs`|`string`|**Required** The originating VCS type. Can be one of "subversion", "git", "mercurial", or "tfvc". |
| 100 | +`vcs_url`|`url`|**Required** The URL of the originating repository. |
| 101 | +`vcs_username`|`string`|If authentication is required, the username to provide to `vcs_url`. |
| 102 | +`vcs_password`|`string`|If authentication is required, the password to provide to `vcs_url`. |
| 103 | +`tfvc_project`|`string`|For a tfvc import, the name of the project that is being imported. |
| 104 | + |
| 105 | +#### Example |
| 106 | + |
| 107 | +<%= json \ |
| 108 | + :vcs => "subversion", |
| 109 | + :vcs_url => "http://svn.mycompany.com/svn/myproject", |
| 110 | + :vcs_username => "octocat", |
| 111 | + :vcs_password => "secret" |
| 112 | +%> |
| 113 | + |
| 114 | +### Response |
| 115 | + |
| 116 | +<%= headers 201, :Location => "https://api.github.com/repos/spraints/socm/import" %> |
| 117 | +<%= json :source_import %> |
| 118 | + |
| 119 | +## Get import progress |
| 120 | + |
| 121 | +View the progress of an import. |
| 122 | + |
| 123 | + GET /repos/:owner/:repo/import |
| 124 | + |
| 125 | +### Response |
| 126 | + |
| 127 | +<%= headers 200 %> |
| 128 | +<%= json :source_import_complete %> |
| 129 | + |
| 130 | +### Import `status` |
| 131 | + |
| 132 | +This section includes details about the possible values of the `status` field of the Import Progress response. |
| 133 | + |
| 134 | +An import that does not have errors will progress through these steps: |
| 135 | + |
| 136 | +* `importing` - the "raw" step of the import is in progress. This is where commit data is fetched from the original repository. The import progress response will include `commit_count` (the total number of raw commits that will be imported) and `percent` (0 - 100, the current progress through the import). |
| 137 | +* `mapping` - the "rewrite" step of the import is in progress. This is where SVN branches are converted to Git branches, and where author updates are applied. The import progress response does not include progress information. |
| 138 | +* `pushing` - the "push" step of the import is in progress. This is where the importer updates the repository on GitHub. The import progress response will include `push_percent`, which is the percent value reported by `git push` when it is "Writing objects". |
| 139 | +* `complete` - the import is complete, and the repository is ready on GitHub. |
| 140 | + |
| 141 | +If there are problems, you will see one of these in the `status` field: |
| 142 | + |
| 143 | +* `auth_failed` - the import requires authentication in order to connect to the original repository. Make another "Start Import" request, and include `vcs_username` and `vcs_password`. |
| 144 | +* `error` - the import encountered an error. The import progress response will include the `failed_step` and an error message. [Contact support](https://github.com/contact?form%5Bsubject%5D=Source+Import+API+error) for more information. |
| 145 | + |
| 146 | +If you query import status for an import started via the web UI, you may also see these states: |
| 147 | + |
| 148 | +* `detecting` - you've entered a URL via the web UI, and the importer is figuring out what type of source control is present at the URL. |
| 149 | +* `detection_needs_auth` - you've entered a URL via the web UI, and the importer needs you to enter authentication credentials in the web UI in order to continue detection. |
| 150 | +* `detection_found_nothing` - the importer didn't recognize any source control at the URL entered via the web UI. |
| 151 | +* `detection_found_multiple` - the importer found several projects or repositories at the provided URL. |
| 152 | +* `waiting_to_push` - the raw and rewrite steps are complete, but a destination GitHub repository hasn't been created yet. |
| 153 | + |
| 154 | +## Get commit authors |
| 155 | + |
| 156 | +Each type of source control system represents authors in a different way. For example, a Git commit author has a display name and an email address, but a Subversion commit author just has a username. The GitHub Importer will make the author information valid, but the author might not be correct. For example, it will change the bare Subversion username `hubot` into something like `hubot <hubot@12341234-abab-fefe-8787-fedcba987654>`. |
| 157 | + |
| 158 | +This API method and the "Map a commit author" method allow you to provide correct Git author information. |
| 159 | + |
| 160 | + GET /repos/:owner/:repo/import/authors |
| 161 | + |
| 162 | +### Parameters |
| 163 | + |
| 164 | +Name | Type | Description |
| 165 | +-----|------|------------ |
| 166 | +`since`|`string`|Only authors found after this id are returned. Provide the highest author ID you've seen so far. New authors may be added to the list at any point while the importer is performing the `raw` step. |
| 167 | + |
| 168 | +### Response |
| 169 | + |
| 170 | +<%= headers 200 %> |
| 171 | +<%= json :source_import_authors %> |
| 172 | + |
| 173 | +## Map a commit author |
| 174 | + |
| 175 | +Update an author's identity for the import. Your application can continue updating authors any time before you push new commits to the repository. |
| 176 | + |
| 177 | + PATCH /repos/:owner/:repo/import/authors/:author_id |
| 178 | + |
| 179 | +### Parameters |
| 180 | + |
| 181 | +Name | Type | Description |
| 182 | +-----|------|-------------- |
| 183 | +`email`|`string`|The new Git author email. |
| 184 | +`name`|`string`|The new Git author name. |
| 185 | + |
| 186 | +### Example |
| 187 | + |
| 188 | +<%= json \ |
| 189 | + :email => "hubot@github.com", |
| 190 | + :name => "Hubot the Robot" |
| 191 | +%> |
| 192 | + |
| 193 | +### Response |
| 194 | + |
| 195 | +<%= headers 200 %> |
| 196 | +<%= json :source_import_author %> |
| 197 | + |
| 198 | +## Cancel an import |
| 199 | + |
| 200 | +Stop an import for a repository. |
| 201 | + |
| 202 | + DELETE /repos/:owner/:repo/import |
| 203 | + |
| 204 | +### Response |
| 205 | + |
| 206 | +<%= headers 204 %> |
0 commit comments