【发布时间】:2018-07-09 16:09:35
【问题描述】:
我无法获取给定提交哈希的文件内容。无论我的参考哈希值如何,我都会从默认分支获取当前文件版本。
我唯一的猜测是 ref 不能是普通哈希,但 documentation 将“ref”描述为“提交/分支/标签的名称”。并且没有提供有关格式的进一步说明。
我用 runkit here 复制了这个问题。并在下面提供了我实际项目中的代码。
async getDifference(): Promise<void> {
let oldFile = await this.gitHubApi.getContent(this.repo.owner.login, this.repo.name, `./${this.file}`, this.oldHash);
let newFile = await this.gitHubApi.getContent(this.repo.owner.login, this.repo.name, `./${this.file}`, this.newHash);
if(oldFile.data.content === newFile.data.content) {
console.log('no differencce');
} else {
...
}
return;
}
public getContent(owner: string, repo: string, path: string, ref?: string): Promise<any> {
if(ref) {
return this.octokit.repos.getContent({
owner: owner,
repo: repo,
path: path,
ref: ref
});
} else {
return this.octokit.repos.getContent({
owner: owner,
repo: repo,
path: path
});
}
}
【问题讨论】:
-
以防万一有什么明显的,你能告诉我们你用提交哈希调用 Octokit 的代码吗?或者它正在生成和请求的 REST URL?谢谢。
-
好的,谢谢。您确定正在使用
if(ref)分支吗? FWIW 我刚刚使用我的一个存储库自己尝试了 API,并且(没有实际检查压缩内容) ref 确实有所作为。 -
@Rup 是的,正在使用 if(ref) 分支。可以肯定的是,我有一个 console.log;为了清楚起见,我只是在提供的代码中省略了它。