gpt4 book ai didi

github - 如何删除 Github 环境

转载 作者:行者123 更新时间:2023-12-03 11:43:34 24 4
gpt4 key购买 nike

我的问题是关于清理 Github 存储库上的“环境”选项卡。

我之前通过 Heroku 部署,使用来自两个独立 Github 分支的自动部署(一个用于登台,一个用于生产)。

这在存储库上创建了一个“环境”选项卡,其中显示了两个 Heroku 环境 - 完全符合预期。

一旦我开始深入研究 Heroku 管道,我现在已经将应用程序配置为从暂存提升到生产环境,因此生产环境不再从分支自动部署。

我的 Github 存储库上的环境选项卡无法删除我不再使用的环境。我似乎在 Github 或 Heroku 上找不到任何地方让 Github“忘记”这个部署环境。

我希望我的问题足够清楚;如果我能详细说明任何事情,请告诉我。

最佳答案

我也制作了一个小网页/脚本,以自动化该过程(我没有安装 Python,而且我没有看到其他人已经制作了一个脚本),这是在线的,将您的信息放入该过程中自动地。
Stackblitz - Github Deployments deleter
2020 年 7 月 18 日编辑:我也将脚本从 Stackblitz 复制到此处的本地片段代码中,以防 Stackblitz 消失:

// RECOMMENDED: Disconnect HEROKU from Github before doing this (though not strictly necessary, I think).
//See https://stackoverflow.com/a/61272173/6569950 for more info.

// PARAMETERS
const TOKEN = ""; // MUST BE `repo_deployments` authorized
const REPO = "your-repo"; // e.g. "monorepo"
const USER_OR_ORG = "your-name"; // e.g. "your-name"

// GLOBAL VARS
const URL = `https://api.github.com/repos/${USER_OR_ORG}/${REPO}/deployments`;
const AUTH_HEADER = `token ${TOKEN}`;

// UTILITY FUNCTIONS
const getAllDeployments = () =>
fetch(`${URL}`, {
headers: {
authorization: AUTH_HEADER
}
}).then(val => val.json());

const makeDeploymentInactive = id =>
fetch(`${URL}/${id}/statuses`, {
method: "POST",
body: JSON.stringify({
state: "inactive"
}),
headers: {
"Content-Type": "application/json",
Accept: "application/vnd.github.ant-man-preview+json",
authorization: AUTH_HEADER
}
}).then(() => id);

const deleteDeployment = id =>
fetch(`${URL}/${id}`, {
method: "DELETE",
headers: {
authorization: AUTH_HEADER
}
}).then(() => id);

// MAIN
getAllDeployments()
.catch(console.error)
.then(res => {
console.log(`${res.length} deployments found`);
return res;
})
.then(val => val.map(({
id
}) => id))
.then(ids => Promise.all(ids.map(id => makeDeploymentInactive(id))))
.then(res => {
console.log(`${res.length} deployments marked as "inactive"`);
return res;
})
.then(ids => Promise.all(ids.map(id => deleteDeployment(id))))
.then(res => {
console.log(`${res.length} deployments deleted`);
return res;
})
.then(finalResult => {
const appDiv = document.getElementById("app");
appDiv.innerHTML = `
<h1>CLEANUP RESULT</h1>
<br>
Removed Deployments: ${finalResult.length}
<br>
<br>Ids:<br>
${JSON.stringify(finalResult)}
<br><br><br><br><br><br>
<p>(Open up the console)</p>
`;
});
h1,
h2 {
font-family: Lato;
}
<div id="app">
<h1>Github Deployment's Cleaner</h1>
<p> You need to put the parameters in!</p>
</div>

关于github - 如何删除 Github 环境,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53452910/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com