import os
import requests
owner = os.environ["OWNER"]
repo = os.environ["REPO"]
token = os.environ["GITHUB_TOKEN"]
url = f"https://api.github.com/repos/{owner}/{repo}/issues/123/comments"
headers = {
"Authorization": f"Bearer {token}",
"Accept": "application/vnd.github+json"
}
data = {"body": "This is a test comment from cURL"}
response = requests.post(url, headers=headers, json=data)
response.raise_for_status()
print(response.json())
import os
import httpx
owner = os.environ["OWNER"]
repo = os.environ["REPO"]
token = os.environ["GITHUB_TOKEN"]
url = f"https://api.github.com/repos/{owner}/{repo}/issues/123/comments"
headers = {
"Authorization": f"Bearer {token}",
"Accept": "application/vnd.github+json"
}
data = {"body": "This is a test comment from cURL"}
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 { env } from 'process';
const owner = env.OWNER;
const repo = env.REPO;
const token = env.GITHUB_TOKEN;
const url = `https://api.github.com/repos/${owner}/${repo}/issues/123/comments`;
const headers = {
'Authorization': `Bearer ${token}`,
'Accept': 'application/vnd.github+json'
};
const data = { body: 'This is a test comment from cURL' };
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 { env } from 'process';
const owner = env.OWNER;
const repo = env.REPO;
const token = env.GITHUB_TOKEN;
const url = `https://api.github.com/repos/${owner}/${repo}/issues/123/comments`;
const headers = {
'Authorization': `Bearer ${token}`,
'Accept': 'application/vnd.github+json'
};
const data = { body: 'This is a test comment from cURL' };
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 Comment struct {
Body string `json:"body"`
}
func main() {
owner := os.Getenv("OWNER")
repo := os.Getenv("REPO")
token := os.Getenv("GITHUB_TOKEN")
url := fmt.Sprintf("https://api.github.com/repos/%s/%s/issues/123/comments", owner, repo)
data := Comment{Body: "This is a test comment from cURL"}
jsonData, _ := json.Marshal(data)
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
if err != nil {
log.Fatal(err)
}
req.Header.Set("Authorization", "Bearer "+token)
req.Header.Set("Accept", "application/vnd.github+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{}
json.NewDecoder(resp.Body).Decode(&result)
fmt.Println(result)
}
<?php
$owner = getenv('OWNER');
$repo = getenv('REPO');
$token = getenv('GITHUB_TOKEN');
$url = "https://api.github.com/repos/{$owner}/{$repo}/issues/123/comments";
$data = ['body' => 'This is a test comment from cURL'];
$options = [
'http' => [
'header' => [
"Authorization: Bearer {$token}",
"Accept: application/vnd.github+json"
],
'method' => 'POST',
'content' => json_encode($data),
'ignore_errors' => true
]
];
$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'
owner = ENV['OWNER']
repo = ENV['REPO']
token = ENV['GITHUB_TOKEN']
uri = URI.parse("https://api.github.com/repos/#{owner}/#{repo}/issues/123/comments")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri)
request['Authorization'] = "Bearer #{token}"
request['Accept'] = 'application/vnd.github+json'
request.body = { body: 'This is a test comment from cURL' }.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 owner = ProcessInfo.processInfo.environment["OWNER"] ?? ""
let repo = ProcessInfo.processInfo.environment["REPO"] ?? ""
let token = ProcessInfo.processInfo.environment["GITHUB_TOKEN"] ?? ""
let url = URL(string: "https://api.github.com/repos/" + owner + "/" + repo + "/issues/123/comments")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
request.setValue("application/vnd.github+json", forHTTPHeaderField: "Accept")
let body: [String: Any] = ["body": "This is a test comment from cURL"]
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")
return
}
if let data = data, let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any] {
print(json)
}
}
task.resume()
RunLoop.main.run()
use std::env;
use reqwest::blocking::Client;
use serde_json::json;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let owner = env::var("OWNER")?;
let repo = env::var("REPO")?;
let token = env::var("GITHUB_TOKEN")?;
let url = format!("https://api.github.com/repos/{}/{}/issues/123/comments", owner, repo);
let client = Client::new();
let response = client
.post(&url)
.header("Authorization", format!("Bearer {}", token))
.header("Accept", "application/vnd.github+json")
.json(&json!({"body": "This is a test comment from cURL"}))
.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.Threading.Tasks;
using System.Text.Json;
class Program
{
static async Task Main()
{
var owner = Environment.GetEnvironmentVariable("OWNER");
var repo = Environment.GetEnvironmentVariable("REPO");
var token = Environment.GetEnvironmentVariable("GITHUB_TOKEN");
var url = $"https://api.github.com/repos/{owner}/{repo}/issues/123/comments";
var data = new { body = "This is a test comment from cURL" };
using var client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/vnd.github+json"));
var response = await client.PostAsJsonAsync(url, data);
response.EnsureSuccessStatusCode();
var result = await response.Content.ReadAsStringAsync();
Console.WriteLine(result);
}
}