You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用C#向GitHub Issue提交评论添加Google Drive文档超链接

在GitHub Issue中添加可直接打开的Google Drive文档链接(使用Octokit)

第一步:配置Google文档的访问权限

要让GitHub上的用户能打开链接,先确保文档权限正确:

  • 打开目标Google文档,点击右上角「共享」
  • 将权限设置为「知道链接的任何人都可查看」(如果仅限特定团队访问,可设置对应组织权限)
  • 复制分享链接,默认格式类似 https://docs.google.com/document/d/文档ID/edit?usp=sharing,把末尾的edit?usp=sharing替换成view或preview,得到可直接打开的链接,比如 https://docs.google.com/document/d/文档ID/view

第二步:修改Octokit代码插入链接

GitHub Issue支持Markdown格式,直接在Issue的Body中用Markdown链接语法插入即可。修改后的代码示例:

using Octokit;
var gitHubClient = new GitHubClient(new ProductHeaderValue("AppName"));
gitHubClient.Credentials = new Credentials("Personal_Access_Token");

string userIssueTitle = "Add Google Document link to this issue";
// 插入Markdown格式的Google Drive链接
string userIssue = @"### This is a new issue
相关文档:[产品需求说明](https://docs.google.com/document/d/你的文档ID/view)";

var (owner, reposName) = ("myGitHubName", "myRepo");
var newIssue = new NewIssue(userIssueTitle) {Body = userIssue};
newIssue.Assignees.Add("ABC");
newIssue.Milestone = 1;
newIssue.Labels.Add("Bug");
newIssue.Labels.Add("Functional");

var issue = await gitHubClient.Issue.Create(owner, reposName, newIssue);
var issueId = issue.Id;
Console.WriteLine($"SUCCESS: your issue id is {issueId} ");

补充说明

  • 也可以用HTML标签写法:<a href="https://docs.google.com/document/d/你的文档ID/view">产品需求说明</a>,GitHub同样会渲染成可点击链接
  • 务必确认文档权限设置正确,否则其他用户点击会出现权限不足提示

内容的提问来源于stack exchange,提问作者BAST23

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 08:01:24