import { Client } from ".."; import { Branch } from "../models/auth"; import { Deployment } from "../models/regional"; import { PullRequest, ReviewApp, SCMRepoLink, } from "../models/regional/scm_repo_links"; import { CreateParams, UpdateParams } from "../params/regional/scm_repo_links"; import { unpackData } from "../utils"; /** * SCM repo links API Client */ export class SCMRepoLinks { /** Scalingo API Client */ _client: Client; /** * Create a new "thematic" client * @param client Scalingo API Client */ constructor(client: Client) { this._client = client; } /** * Get the repo link associated to an application. * @see https://developers.scalingo.com/scm_repo_link#get-an-integration-link * @param appID ID of the application * @return Promise that when resolved returns a SCMRepoLink */ find(appID: string): Promise { return unpackData( this._client.apiClient().get(`/apps/${appID}/scm_repo_link`), "scm_repo_link", ); } /** * Create a SCM repo link. * @see https://developers.scalingo.com/scm_repo_link#create-a-scm-integration-link * @param appID ID of the application * @param opts SCM repo link information * @return Promise that when resolved returns the SCMRepoLink created. */ create(appID: string, opts: CreateParams): Promise { return unpackData( this._client .apiClient() .post(`/apps/${appID}/scm_repo_link`, { scm_repo_link: opts }), "scm_repo_link", ); } /** * Update a SCM integration link. * @see https://developers.scalingo.com/scm_repo_link * @param appID ID of the application * @param opts SCM repo link information to update * @return Promise that when resolved returns the SCMRepoLink updated. */ update(appID: string, opts: UpdateParams): Promise { return unpackData( this._client .apiClient() .patch(`/apps/${appID}/scm_repo_link`, { scm_repo_link: opts }), "scm_repo_link", ); } /** * Delete a SCM repo link * @see https://developers.scalingo.com/scm_repo_link#delete-an-integration-link * @param {String} appID ID of the application * @return {Promise} Promise that resolves when the link is deleted. */ destroy(appID: string): Promise { return unpackData( this._client.apiClient().delete(`/apps/${appID}/scm_repo_link`), ); } /** * Manually deploy an application * @see https://developers.scalingo.com/scm_repo_link#manual-deploy * @param appID ID of the application * @param branch Name of the branch to deploy. * @return Promise that when resolved returns the Deployment started. * @todo Promise */ manualDeploy(appID: string, branch: string): Promise { return unpackData( this._client .apiClient() .post(`/apps/${appID}/scm_repo_link/manual_deploy`, { branch, }), "deployment", ); } /** * Manually deploy a review app of the given pull/merge request * @see https://developers.scalingo.com/scm_repo_link#manual-review-app * @param appID ID of the application * @param pullRequestID ID of the pull/merge request to deploy * @return Promise that when resolved returns the App created. * @todo Promise */ manualReviewApp(appID: string, pullRequestID: string): Promise { return unpackData( this._client .apiClient() .post(`/apps/${appID}/scm_repo_link/manual_review_app`, { pull_request_id: pullRequestID, }), "review_app", ); } /** * List the branches of the remote repository. * @see https://developers.scalingo.com/scm_repo_link * @param appID ID of the application * @return Promise that when resolved returns an array of branches. * @todo Promise */ branches(appID: string): Promise { return unpackData( this._client.apiClient().get(`/apps/${appID}/scm_repo_link/branches`), "branches", ); } /** * List the merge/pull requests of the remote repository. * @see https://developers.scalingo.com/scm_repo_link * @param appID ID of the application * @return Promise that when resolved returns an array of pull requests. * @todo Promise */ pulls(appID: string): Promise { return unpackData( this._client.apiClient().get(`/apps/${appID}/scm_repo_link/pulls`), "pulls", ); } /** * List the review apps of the supplied app. * @param appID ID of the application * @return Promise that when resolved returns an array of review apps. * @todo Promise */ reviewApps(appID: string): Promise { return unpackData( this._client.apiClient().get(`/apps/${appID}/scm_repo_link/review_apps`), "review_apps", ); } } export default SCMRepoLinks;