Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我们如何使用GitHub Rest API在GitHub中使用其他存储库内容和模板创建存储库_Github_Github Api_Github Actions_Restapi_Github Projects - Fatal编程技术网

我们如何使用GitHub Rest API在GitHub中使用其他存储库内容和模板创建存储库

我们如何使用GitHub Rest API在GitHub中使用其他存储库内容和模板创建存储库,github,github-api,github-actions,restapi,github-projects,Github,Github Api,Github Actions,Restapi,Github Projects,我已经使用getrepoapi()来获取存储库的详细信息。现在我想用我的“myRepoName”中的内容和文件创建一个新的存储库。我该如何实现这一点。 创建API(Post)(如果源存储库是模板存储库(),则可以使用以下API: 注意:创建和使用存储库模板目前可供开发人员预览。要在预览期间访问此新端点,必须在Accept标头中提供自定义媒体类型: application/vnd.github.baptiste预览+json 使用存储库模板创建新存储库。使用template_owner和templ

我已经使用getrepoapi()来获取存储库的详细信息。现在我想用我的“myRepoName”中的内容和文件创建一个新的存储库。我该如何实现这一点。
创建API(Post)(

如果源存储库是模板存储库(),则可以使用以下API:

注意:创建和使用存储库模板目前可供开发人员预览。要在预览期间访问此新端点,必须在Accept标头中提供自定义媒体类型:

application/vnd.github.baptiste预览+json

使用存储库模板创建新存储库。使用template_owner和template_repo路由参数指定要用作模板的存储库。经过身份验证的用户必须拥有或是拥有存储库的组织的成员。要检查存储库是否可用作模板,请使用get a repository端点获取存储库的信息,并检查is_template键是否为true

POST/repos/:template\u owner/:template\u repo/generate

参数

Name Type Description owner string The organization or person who will own the new repository. To > >create a new repository in an organization, the authenticated user must be a member >of the specified organization. name string Required. The name of the new repository. description string A short description of the new repository. private boolean Either true to create a new private repository or false to >create a new public one. Default: false 名称类型说明 所有者字符串将拥有新存储库的组织或人员。若要>>在组织中创建新存储库,经过身份验证的用户必须是指定组织的成员>。 需要名称字符串。新存储库的名称。 描述字符串新存储库的简短描述。 private boolean为true可创建新的私有存储库,为false可>创建新的公共存储库。默认值:false

使用node js v12.18.1或更高版本和octokit/rest api v17:只需从github配置文件设置生成个人访问令牌,并使用以下代码:

require('dotenv').config();
const{Octokit}=require('@Octokit/rest');
const clientWithAuth=新的Octokit({
auth:process.env.TOKEN,//创建github个人令牌
});
常量main=async()=>{
const owner=process.env.owner;
const username=process.env.username;
const response=wait clientWithAuth.repos.createUsingTemplate({
模板所有者:所有者,
模板报告:“模板测试”,
名称:`template-${username}`,
});

console.log('repository已成功创建我只能在我的github帐户中创建模板api。如果该模板属于其他帐户,并且我希望在我的github帐户中创建回购模板,该怎么办?根据
似乎不可能使用template\u owner和template\u repo route参数指定要用作tem的存储库图版。经过身份验证的用户必须拥有或是拥有存储库的组织的成员
是否有其他方法可以使用repo模板在我们的git帐户中创建具有相同内容的repo。据我所知,只有使用GitHub UI才有可能