GitHub App リポジトリの連携
Square Cloud GitHub App を通じて、GitHub のリポジトリとブランチをアプリケーションに連携します。
POST
/
v2
/
apps
/
{app_id}
/
deploy
/
github-app
GitHub App リポジトリの連携
curl --request POST \
--url https://api.squarecloud.app/v2/apps/{app_id}/deploy/github-app \
--header 'Authorization: <authorization>' \
--header 'Content-Type: application/json' \
--data '
{
"repositoryName": "<string>",
"repositoryBranch": "<string>"
}
'import requests
url = "https://api.squarecloud.app/v2/apps/{app_id}/deploy/github-app"
payload = {
"repositoryName": "<string>",
"repositoryBranch": "<string>"
}
headers = {
"Authorization": "<authorization>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<authorization>', 'Content-Type': 'application/json'},
body: JSON.stringify({repositoryName: '<string>', repositoryBranch: '<string>'})
};
fetch('https://api.squarecloud.app/v2/apps/{app_id}/deploy/github-app', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.squarecloud.app/v2/apps/{app_id}/deploy/github-app",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'repositoryName' => '<string>',
'repositoryBranch' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.squarecloud.app/v2/apps/{app_id}/deploy/github-app"
payload := strings.NewReader("{\n \"repositoryName\": \"<string>\",\n \"repositoryBranch\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<authorization>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.squarecloud.app/v2/apps/{app_id}/deploy/github-app")
.header("Authorization", "<authorization>")
.header("Content-Type", "application/json")
.body("{\n \"repositoryName\": \"<string>\",\n \"repositoryBranch\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.squarecloud.app/v2/apps/{app_id}/deploy/github-app")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<authorization>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"repositoryName\": \"<string>\",\n \"repositoryBranch\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"status": "success",
"response": {
"repository": {
"id": 1234567,
"full_name": "octocat/hello-world",
"branch": "main"
}
}
}
このエンドポイントは、Square Cloud GitHub App を通じてアプリケーションを GitHub のリポジトリとブランチに連携し、そのブランチへの push のたびにアプリケーションがデプロイされるようにします。GitHub Webhook の設定 に代わる推奨の方法で、パーソナルアクセストークンは保存されず、各デプロイはコミット上の Check Run として表示されます。
呼び出す前に、GitHub アカウントを Square Cloud に接続し、Square Cloud GitHub App をリポジトリにインストールしてください。リポジトリは、ご自身の GitHub アカウントが保有するインストールの対象になっている必要があります。そうでない場合、リクエストは
REPOSITORY_NOT_AVAILABLE で失敗します。apps:deploy スコープを持つ API キーで利用でき、呼び出せるのはアプリケーションの所有者のみです。
1 つのアプリケーションが持てる GitHub App 連携は一度に 1 つだけです。別のリポジトリを連携する前に、現在のリポジトリを 連携解除 してください。また、同じリポジトリとブランチを自分の 2 つのアプリケーションに連携することはできません。連携すると、現在のデプロイメントの取得 のキャッシュされたレスポンスは無効になります。呼び出しはユーザーごとに 60 秒あたり 3 回までレート制限されており、この上限は連携解除と共有されます。
パラメータ
string
必須
アプリケーションの ID です。アプリケーションのダッシュボードの URL で確認できます。
string
必須
リポジトリのフルネームです。
owner/repository の形式で指定します。string
必須
push によってアプリケーションをデプロイするブランチです。最大 256 文字で、リポジトリ内に存在している必要があります。
レスポンス
string
呼び出しが成功したかどうかを示します。成功した場合は
success、失敗した場合は error です。object
{
"status": "success",
"response": {
"repository": {
"id": 1234567,
"full_name": "octocat/hello-world",
"branch": "main"
}
}
}
一般的なエラー
| コード | HTTP | 説明 |
|---|---|---|
MISSING_REQUIRED_FIELDS | 400 | repositoryName または repositoryBranch がありません。 |
INVALID_BRANCH_LENGTH | 400 | ブランチ名が 256 文字を超えています。 |
BRANCH_NOT_FOUND | 400 | ブランチがリポジトリに存在しません。 |
GIT_ALREADY_CONFIGURED | 400 | アプリケーションにはすでに GitHub App リポジトリが連携されています。先に連携を解除してください。 |
REPOSITORY_NOT_AVAILABLE | 403 | Square Cloud GitHub App が、ご自身の GitHub アカウント経由でリポジトリにインストールされていません。 |
REPOSITORY_NOT_FOUND | 404 | リポジトリが存在しないか、ご自身の GitHub アカウントから参照できません。 |
APP_NOT_FOUND | 404 | アプリケーションが存在しないか、あなたが所有者ではありません。 |
REPOSITORY_BRANCH_ALREADY_CONFIGURED | 409 | このリポジトリとブランチは、すでに別のアプリケーションに連携されています。 |
⌘I
GitHub App リポジトリの連携
curl --request POST \
--url https://api.squarecloud.app/v2/apps/{app_id}/deploy/github-app \
--header 'Authorization: <authorization>' \
--header 'Content-Type: application/json' \
--data '
{
"repositoryName": "<string>",
"repositoryBranch": "<string>"
}
'import requests
url = "https://api.squarecloud.app/v2/apps/{app_id}/deploy/github-app"
payload = {
"repositoryName": "<string>",
"repositoryBranch": "<string>"
}
headers = {
"Authorization": "<authorization>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<authorization>', 'Content-Type': 'application/json'},
body: JSON.stringify({repositoryName: '<string>', repositoryBranch: '<string>'})
};
fetch('https://api.squarecloud.app/v2/apps/{app_id}/deploy/github-app', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.squarecloud.app/v2/apps/{app_id}/deploy/github-app",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'repositoryName' => '<string>',
'repositoryBranch' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.squarecloud.app/v2/apps/{app_id}/deploy/github-app"
payload := strings.NewReader("{\n \"repositoryName\": \"<string>\",\n \"repositoryBranch\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<authorization>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.squarecloud.app/v2/apps/{app_id}/deploy/github-app")
.header("Authorization", "<authorization>")
.header("Content-Type", "application/json")
.body("{\n \"repositoryName\": \"<string>\",\n \"repositoryBranch\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.squarecloud.app/v2/apps/{app_id}/deploy/github-app")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<authorization>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"repositoryName\": \"<string>\",\n \"repositoryBranch\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"status": "success",
"response": {
"repository": {
"id": 1234567,
"full_name": "octocat/hello-world",
"branch": "main"
}
}
}

