Skip to content

Commit bc3ea1b

Browse files
committed
fix: patch environment for non-pr actions
1 parent 7be3180 commit bc3ea1b

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

dist/index.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
290290
Object.defineProperty(exports, "__esModule", { value: true });
291291
const github = __importStar(__webpack_require__(469));
292292
const githubClient_1 = __importDefault(__webpack_require__(119));
293+
const dayjs_1 = __importDefault(__webpack_require__(874));
293294
exports.default = (repo, environmentPrefix) => __awaiter(void 0, void 0, void 0, function* () {
294-
const environment = `${environmentPrefix || 'PR-'}${github.context.payload.pull_request.number}`;
295+
const githubEventName = github.context.eventName;
296+
const environment = githubEventName === 'pull_request'
297+
? `${environmentPrefix || 'PR-'}${github.context.payload.pull_request.number}`
298+
: `${environmentPrefix || 'ACTION-'}${dayjs_1.default().format('DD-MM-YYYY-hh:mma')}`;
295299
const deployments = yield githubClient_1.default.repos.listDeployments({
296300
repo: repo.repo,
297301
owner: repo.owner,
@@ -13774,9 +13778,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
1377413778
Object.defineProperty(exports, "__esModule", { value: true });
1377513779
const github = __importStar(__webpack_require__(469));
1377613780
const githubClient_1 = __importDefault(__webpack_require__(119));
13781+
const dayjs_1 = __importDefault(__webpack_require__(874));
1377713782
exports.default = (repo, environmentPrefix) => __awaiter(void 0, void 0, void 0, function* () {
1377813783
var _a, _b;
13779-
const environment = `${environmentPrefix || 'PR-'}${github.context.payload.pull_request.number}`;
13784+
const githubEventName = github.context.eventName;
13785+
const environment = githubEventName === 'pull_request'
13786+
? `${environmentPrefix || 'PR-'}${github.context.payload.pull_request.number}`
13787+
: `${environmentPrefix || 'ACTION-'}${dayjs_1.default().format('DD-MM-YYYY-hh:mma')}`;
1378013788
const deployments = yield githubClient_1.default.graphql(`
1378113789
query GetDeployments($owner: String!, $repo: String!, $environments: [String!]) {
1378213790
repository(owner: $owner, name: $repo) {

src/utils/deactivateDeployments.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as github from '@actions/github'
22
import githubClient from '../githubClient'
3+
import dayjs from 'dayjs'
34

45
export default async (
56
repo: {
@@ -8,9 +9,11 @@ export default async (
89
},
910
environmentPrefix: string
1011
) => {
11-
const environment = `${environmentPrefix || 'PR-'}${
12-
github.context.payload.pull_request!.number
13-
}`
12+
const githubEventName = github.context.eventName
13+
const environment =
14+
githubEventName === 'pull_request'
15+
? `${environmentPrefix || 'PR-'}${github.context.payload.pull_request!.number}`
16+
: `${environmentPrefix || 'ACTION-'}${dayjs().format('DD-MM-YYYY-hh:mma')}`
1417

1518
const deployments = await githubClient.repos.listDeployments({
1619
repo: repo.repo,

src/utils/deleteDeployments.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as github from '@actions/github'
22
import githubClient from '../githubClient'
3+
import dayjs from 'dayjs'
34

45
export default async (
56
repo: {
@@ -8,9 +9,11 @@ export default async (
89
},
910
environmentPrefix: string
1011
) => {
11-
const environment = `${environmentPrefix || 'PR-'}${
12-
github.context.payload.pull_request!.number
13-
}`
12+
const githubEventName = github.context.eventName
13+
const environment =
14+
githubEventName === 'pull_request'
15+
? `${environmentPrefix || 'PR-'}${github.context.payload.pull_request!.number}`
16+
: `${environmentPrefix || 'ACTION-'}${dayjs().format('DD-MM-YYYY-hh:mma')}`
1417

1518
const deployments = await githubClient.graphql(
1619
`

0 commit comments

Comments
 (0)