MCPcopy
hub / github.com/leonhartX/gas-github / createBranch

Method createBranch

src/scm/github.js:433–488  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

431 }
432
433 createBranch() {
434 const branch = $('#new-branch-name').val();
435 if (!branch || branch === '') return;
436 return new Promise((resolve, reject) => {
437 getGitHubJSON(
438 `${this.baseUrl}/repos/${getRepo().fullName}/git/refs/heads/${getBranch()}`,
439 this.accessToken)
440 .then(resolve)
441 .fail(reject)
442 })
443 .then(response => {
444 if (response.object) {
445 return response.object.sha;
446 } else {
447 return getGitHubJSON(
448 `${this.baseUrl}/repos/${getRepo().fullName}/git/refs/heads`,
449 this.accessToken)
450 .then(response => {
451 return response[0].object.sha;
452 })
453 }
454 })
455 .then(sha => {
456 const payload = {
457 ref: `refs/heads/${branch}`,
458 sha: sha
459 };
460 return $.ajax({
461 url: `${this.baseUrl}/repos/${getRepo().fullName}/git/refs`,
462 headers: {
463 'Authorization': `token ${this.accessToken}`
464 },
465 method: 'POST',
466 crossDomain: true,
467 dataType: 'json',
468 contentType: 'application/json',
469 data: JSON.stringify(payload)
470 });
471 })
472 .then(response => {
473 Object.assign(context.bindBranch, {
474 [getId()]: branch
475 });
476 chrome.storage.sync.set({
477 bindBranch: context.bindBranch
478 });
479 return branch;
480 })
481 .catch(err => {
482 if (err.status === 409) {
483 throw new Error('Cannot create branch in empty repository with API, try to create branch in Github.');
484 } else {
485 throw new Error('Failed to create new branch.');
486 }
487 });
488 }
489
490 followPaginate(data) {

Callers

nothing calls this directly

Calls 4

getGitHubJSONFunction · 0.85
getRepoFunction · 0.85
getBranchFunction · 0.85
getIdFunction · 0.85

Tested by

no test coverage detected