api - 如何使用Rust通过访问 token 提交新的github问题

标签 api github rust

我正在尝试编写一个rust脚本,该脚本使用github访问 token 将具有给定名称,标签和主体的问题提交给特定的存储库。我已经找到了github-rs和octocrab,但是无法弄清楚这个确切的函数是如何工作的。
更新
这是使用rust-curl的代码:

use std::io::Read;
use curl::easy::{Easy, List};

fn main() {
    let mut data = r#"{
        "title": "Found a bug",
        "body": "I'm having a problem with this.",
        "labels": [
          "bug"
        ]
      }"#.as_bytes();
    let mut easy = Easy::new();
    easy.url("https://api.github.com").unwrap();

    let mut list = List::new();
    list.append("Authorization: token TOKEN_HERE").unwrap();
    easy.http_headers(list).unwrap();
    easy.perform().unwrap();
    easy.post(true).unwrap();
    easy.post_field_size(data.len() as u64).unwrap();
    let mut transfer = easy.transfer();
    transfer.read_function(|buf| {
        Ok(data.read(buf).unwrap_or(0))
    }).unwrap();
    transfer.perform().unwrap();
}

最佳答案

如果这些库中没有简单的方法,则可以使用 alexcrichton/curl-rust
它确实允许您添加custom headers,包括您可以看到used here"Authorization: token MY_TOKEN_NUMBERS",它将对您进行身份验证。
从那里,您的curl调用(使用rust )可以使用GitHub API "create issue" endpoint:

POST /repos/:owner/:repo/issues
与数据:
{
  "title": "Found a bug",
  "body": "I'm having a problem with this.",
  "assignees": [
    "octocat"
  ],
  "milestone": 1,
  "labels": [
    "bug"
  ]
}

关于api - 如何使用Rust通过访问 token 提交新的github问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63430323/

相关文章:

api - 此 key 未授权用于此服务

git - 如果你已经 fork 了一个 repo 并且你是 fork 的唯一用户,那么在推送之后 rebase 是否可以?

linux - 用于 Linux 进程监控的 Python Zabbix API

api - Azure 管理 API 接受的资源类型,版本 : 2015-06-01-preview

php - 如何从Google Analytics(分析)API获取最佳位置?

github 下载 - 它只能是平面文件系统吗?

mysql - 如何有选择地为 github repo 导出 mysql 数据

asynchronous - 从 Tokio 应用程序使用 Actix:混合 actix_web::main 和 tokio::main?

rust - 数字数组(不是 Vec)的类型是什么?

vector - 如何将整数向量连接成单个整数?