import os
import requests
url = f"https://api.github.com/repos/{os.environ['GITHUB_OWNER']}/{os.environ['GITHUB_REPO']}/releases"
headers = {
"Authorization": f"token {os.environ['GITHUB_TOKEN']}",
"Accept": "application/vnd.github.v3+json"
}
data = {
"tag_name": "v1.0.0",
"name": "Release v1.0.0",
"body": "Initial release"
}
response = requests.post(url, headers=headers, json=data)
response.raise_for_status()
print(response.json())
import os
import httpx
url = f"https://api.github.com/repos/{os.environ['GITHUB_OWNER']}/{os.environ['GITHUB_REPO']}/releases"
headers = {
"Authorization": f"token {os.environ['GITHUB_TOKEN']}",
"Accept": "application/vnd.github.v3+json"
}
data = {
"tag_name": "v1.0.0",
"name": "Release v1.0.0",
"body": "Initial release"
}
with httpx.Client() as client:
response = client.post(url, headers=headers, json=data)
response.raise_for_status()
print(response.json())
import fetch from 'node-fetch';
import * as process from 'process';
const url = `https://api.github.com/repos/${process.env.GITHUB_OWNER}/${process.env.GITHUB_REPO}/releases`;
const headers = {
"Authorization": `token ${process.env.GITHUB_TOKEN}`,
"Accept": "application/vnd.github.v3+json"
};
const data = {
tag_name: "v1.0.0",
name: "Release v1.0.0",
body: "Initial release"
};
fetch(url, {
method: 'POST',
headers,
body: JSON.stringify(data)
})
.then(res => {
if (!res.ok) throw new Error(`HTTP error! status: ${res.status}`);
return res.json();
})
.then(console.log)
.catch(console.error);
import axios from 'axios';
import * as process from 'process';
const url = `https://api.github.com/repos/${process.env.GITHUB_OWNER}/${process.env.GITHUB_REPO}/releases`;
const headers = {
"Authorization": `token ${process.env.GITHUB_TOKEN}`,
"Accept": "application/vnd.github.v3+json"
};
const data = {
tag_name: "v1.0.0",
name: "Release v1.0.0",
body: "Initial release"
};
axios.post(url, data, { headers })
.then(res => {
console.log(res.data);
})
.catch(err => {
console.error(err.message);
});
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
"os"
)
type Release struct {
TagName string `json:"tag_name"`
Name string `json:"name"`
Body string `json:"body"`
}
func main() {
url := fmt.Sprintf("https://api.github.com/repos/%s/%s/releases",
os.Getenv("GITHUB_OWNER"), os.Getenv("GITHUB_REPO"))
release := Release{
TagName: "v1.0.0",
Name: "Release v1.0.0",
Body: "Initial release",
}
body, err := json.Marshal(release)
if err != nil {
log.Fatal(err)
}
req, err := http.NewRequest("POST", url, bytes.NewBuffer(body))
if err != nil {
log.Fatal(err)
}
req.Header.Set("Authorization", fmt.Sprintf("token %s", os.Getenv("GITHUB_TOKEN")))
req.Header.Set("Accept", "application/vnd.github.v3+json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
log.Fatalf("Request failed with status: %s", resp.Status)
}
var result map[string]interface{}
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
log.Fatal(err)
}
fmt.Println(result)
}
<?php
$url = sprintf(
'https://api.github.com/repos/%s/%s/releases',
urlencode(getenv('GITHUB_OWNER')),
urlencode(getenv('GITHUB_REPO'))
);
$data = [
'tag_name' => 'v1.0.0',
'name' => 'Release v1.0.0',
'body' => 'Initial release'
];
$options = [
'http' => [
'method' => 'POST',
'header' => [
'Authorization: token ' . getenv('GITHUB_TOKEN'),
'Accept: application/vnd.github.v3+json',
'Content-Type: application/json'
],
'content' => json_encode($data)
]
];
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === false) {
throw new Exception('Request failed');
}
$response = json_decode($result, true);
print_r($response);
require 'net/http'
require 'json'
require 'uri'
uri = URI.parse("https://api.github.com/repos/#{ENV['GITHUB_OWNER']}/#{ENV['GITHUB_REPO']}/releases")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri)
request['Authorization'] = "token #{ENV['GITHUB_TOKEN']}"
request['Accept'] = 'application/vnd.github.v3+json'
request.body = {
tag_name: 'v1.0.0',
name: 'Release v1.0.0',
body: 'Initial release'
}.to_json
response = http.request(request)
unless response.is_a?(Net::HTTPSuccess)
raise "Request failed with status #{response.code}"
end
puts JSON.parse(response.body)
import Foundation
let url = URL(string: "https://api.github.com/repos/$(ProcessInfo.processInfo.environment["GITHUB_OWNER"] ?? "")/$(ProcessInfo.processInfo.environment["GITHUB_REPO"] ?? "")/releases")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("token \(ProcessInfo.processInfo.environment["GITHUB_TOKEN"] ?? "")", forHTTPHeaderField: "Authorization")
request.setValue("application/vnd.github.v3+json", forHTTPHeaderField: "Accept")
let body: [String: Any] = [
"tag_name": "v1.0.0",
"name": "Release v1.0.0",
"body": "Initial release"
]
request.httpBody = try? JSONSerialization.data(withJSONObject: body)
let task = URLSession.shared.dataTask(with: request) { data, response, error in
if let error = error {
print("Error: \(error)")
return
}
guard let httpResponse = response as? HTTPURLResponse, httpResponse.statusCode == 200 else {
print("Request failed with status: \((response as? HTTPURLResponse)?.statusCode ?? 0)")
return
}
if let data = data, let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any] {
print(json)
}
}
task.resume()
RunLoop.main.run()
use reqwest::blocking::Client;
use serde_json::json;
use std::env;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::new();
let owner = env::var("GITHUB_OWNER")?;
let repo = env::var("GITHUB_REPO")?;
let token = env::var("GITHUB_TOKEN")?;
let url = format!("https://api.github.com/repos/{}/{}/releases", owner, repo);
let body = json!({
"tag_name": "v1.0.0",
"name": "Release v1.0.0",
"body": "Initial release"
});
let response = client
.post(&url)
.header("Authorization", format!("token {}", token))
.header("Accept", "application/vnd.github.v3+json")
.json(&body)
.send()?;
if !response.status().is_success() {
return Err(format!("Request failed with status: {}", response.status()).into());
}
let json: serde_json::Value = response.json()?;
println!("{}", json);
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 client = new HttpClient();
var owner = Environment.GetEnvironmentVariable("GITHUB_OWNER");
var repo = Environment.GetEnvironmentVariable("GITHUB_REPO");
var token = Environment.GetEnvironmentVariable("GITHUB_TOKEN");
var url = $"https://api.github.com/repos/{owner}/{repo}/releases";
var body = new {
tag_name = "v1.0.0",
name = "Release v1.0.0",
body = "Initial release"
};
var content = new StringContent(JsonSerializer.Serialize(body));
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("token", token);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/vnd.github.v3+json"));
var response = await client.PostAsync(url, content);
response.EnsureSuccessStatusCode();
var responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
}
}