import os
import requests
response = requests.post(
url="https://api.github.com/repos/${GITHUB_OWNER}/${GITHUB_REPO}/releases",
headers={"Authorization": f"Bearer {os.environ['GITHUB_TOKEN']}"},
json={"tag_name": "v1.0.0", "name": "Release v1.0.0", "body": "Initial release"}
)
response.raise_for_status()
import os
import httpx
response = httpx.post(
url="https://api.github.com/repos/${GITHUB_OWNER}/${GITHUB_REPO}/releases",
headers={"Authorization": f"Bearer {os.environ['GITHUB_TOKEN']}"},
json={"tag_name": "v1.0.0", "name": "Release v1.0.0", "body": "Initial release"}
)
response.raise_for_status()
import fetch from 'node-fetch';
import { config } from 'dotenv';
config();
const response = await fetch("https://api.github.com/repos/${GITHUB_OWNER}/${GITHUB_REPO}/releases", {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.GITHUB_TOKEN}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
tag_name: "v1.0.0",
name: "Release v1.0.0",
body: "Initial release"
})
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
import axios from 'axios';
import { config } from 'dotenv';
config();
const response = await axios.post(
"https://api.github.com/repos/${GITHUB_OWNER}/${GITHUB_REPO}/releases",
{
tag_name: "v1.0.0",
name: "Release v1.0.0",
body: "Initial release"
},
{
headers: {
'Authorization': `Bearer ${process.env.GITHUB_TOKEN}`,
'Content-Type': 'application/json'
}
}
);
if (response.status >= 400) {
throw new Error(`HTTP error! status: ${response.status}`);
}
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"os"
)
func main() {
token := os.Getenv("GITHUB_TOKEN")
owner := os.Getenv("GITHUB_OWNER")
repo := os.Getenv("GITHUB_REPO")
body := map[string]string{
"tag_name": "v1.0.0",
"name": "Release v1.0.0",
"body": "Initial release",
}
jsonBody, _ := json.Marshal(body)
req, err := http.NewRequest(
"POST",
fmt.Sprintf("https://api.github.com/repos/%s/%s/releases", owner, repo),
bytes.NewBuffer(jsonBody),
)
if err != nil {
panic(err)
}
req.Header.Set("Authorization", "Bearer "+token)
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
if resp.StatusCode >= 400 {
body, _ := io.ReadAll(resp.Body)
panic(fmt.Sprintf("HTTP error! status: %d, body: %s", resp.StatusCode, body))
}
}
<?php
$token = getenv('GITHUB_TOKEN');
$owner = getenv('GITHUB_OWNER');
$repo = getenv('GITHUB_REPO');
$url = "https://api.github.com/repos/{$owner}/{$repo}/releases";
$data = [
'tag_name' => 'v1.0.0',
'name' => 'Release v1.0.0',
'body' => 'Initial release'
];
$options = [
'http' => [
'header' => "Authorization: Bearer {$token}\r\n",
'method' => 'POST',
'content' => json_encode($data),
'ignore_errors' => true
]
];
$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);
if ($http_response_header[0] !== 'HTTP/1.1 201 Created' && $http_response_header[0] !== 'HTTP/2 201') {
throw new Exception("HTTP error! status: " . $http_response_header[0]);
}
var_dump($response);
require 'net/http'
require 'json'
require 'dotenv/load'
token = ENV['GITHUB_TOKEN']
owner = ENV['GITHUB_OWNER']
repo = ENV['GITHUB_REPO']
uri = URI("https://api.github.com/repos/#{owner}/#{repo}/releases")
req = Net::HTTP::Post.new(uri)
req['Authorization'] = "Bearer #{token}"
req['Content-Type'] = 'application/json'
req.body = {
tag_name: 'v1.0.0',
name: 'Release v1.0.0',
body: 'Initial release'
}.to_json
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
http.request(req)
end
unless res.is_a?(Net::HTTPSuccess)
raise "HTTP error! status: #{res.code}"
end
import Foundation
let token = ProcessInfo.processInfo.environment["GITHUB_TOKEN"] ?? ""
let owner = ProcessInfo.processInfo.environment["GITHUB_OWNER"] ?? ""
let repo = ProcessInfo.processInfo.environment["GITHUB_REPO"] ?? ""
let url = URL(string: "https://api.github.com/repos/\\(owner)/\\(repo)/releases")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("Bearer \(token)", forHTTPHeaderField: "Authorization")
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
let body: [String: String] = [
"tag_name": "v1.0.0",
"name": "Release v1.0.0",
"body": "Initial release"
]
request.httpBody = try JSONSerialization.data(withJSONObject: body)
let (data, response) = try await URLSession.shared.data(for: request)
if let httpResponse = response as? HTTPURLResponse, httpResponse.statusCode >= 400 {
throw URLError(.badServerResponse)
}
use reqwest;
use serde_json::json;
use std::env;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let token = env::var("GITHUB_TOKEN")?;
let owner = env::var("GITHUB_OWNER")?;
let repo = env::var("GITHUB_REPO")?;
let client = reqwest::Client::new();
let response = client
.post(format!("https://api.github.com/repos/{}/{}/releases", owner, repo))
.header("Authorization", format!("Bearer {}", token))
.json(&json!({
"tag_name": "v1.0.0",
"name": "Release v1.0.0",
"body": "Initial release"
}))
.send()
.await?;
if !response.status().is_success() {
return Err(format!("HTTP error! status: {}", response.status()).into());
}
Ok(())
}
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text.Json;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
var token = Environment.GetEnvironmentVariable("GITHUB_TOKEN");
var owner = Environment.GetEnvironmentVariable("GITHUB_OWNER");
var repo = Environment.GetEnvironmentVariable("GITHUB_REPO");
using var client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var body = new {
tag_name = "v1.0.0",
name = "Release v1.0.0",
body = "Initial release"
};
var response = await client.PostAsJsonAsync(
$"https://api.github.com/repos/{owner}/{repo}/releases",
body
);
if (!response.IsSuccessStatusCode)
{
throw new Exception($"HTTP error! status: {response.StatusCode}");
}
}
}