Skip to content

Commit

Permalink
feat: add warning if not part of the nearform-actions org (#113)
Browse files Browse the repository at this point in the history
* feat: add warning if not part of the nearform-actions org

* fix: update warning text to be more informative
  • Loading branch information
gregoryduckworth authored Jan 27, 2023
1 parent 90f26b3 commit 51eb375
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 8 deletions.
Empty file modified .husky/commit-msg
100644 → 100755
Empty file.
Empty file modified .husky/pre-commit
100644 → 100755
Empty file.
20 changes: 18 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const core = require('@actions/core')
*/
function logActionRefWarning() {
const actionRef = process.env.GITHUB_ACTION_REF
const repoName = process.env.GITHUB_REPOSITORY
const repoName = process.env.GITHUB_ACTION_REPOSITORY

if (actionRef === 'main' || actionRef === 'master') {
core.warning(
Expand All @@ -23,6 +23,22 @@ function logActionRefWarning() {
}
}

/**
* Displays warning message if the repository is under the nearform organisation
*/
function logRepoWarning() {
const repoName = process.env.GITHUB_ACTION_REPOSITORY
const repoOrg = repoName.split('/')[0]

if (repoOrg != 'nearform-actions') {
core.warning(
`'${repoOrg}' is no longer a valid organisation for this action.` +
`Please update it to be under the 'nearform-actions' organisation.`
)
}
}

module.exports = {
logActionRefWarning
logActionRefWarning,
logRepoWarning
}
49 changes: 43 additions & 6 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ const setup = () => {
test('should return warning if actionRef is master', async ({ teardown }) => {
teardown(() => {
process.env.GITHUB_ACTION_REF = undefined
process.env.GITHUB_REPOSITORY = undefined
process.env.GITHUB_ACTION_REPOSITORY = undefined
})

const { toolkit, warningStub } = setup()

process.env.GITHUB_ACTION_REF = 'master'
process.env.GITHUB_REPOSITORY = 'nearform/test-repo'
process.env.GITHUB_ACTION_REPOSITORY = 'nearform/test-repo'
toolkit.logActionRefWarning()

sinon.assert.calledOnceWithMatch(
Expand All @@ -37,13 +37,13 @@ test('should return warning if actionRef is master', async ({ teardown }) => {
test('should return warning if actionRef is main', async ({ teardown }) => {
teardown(() => {
process.env.GITHUB_ACTION_REF = undefined
process.env.GITHUB_REPOSITORY = undefined
process.env.GITHUB_ACTION_REPOSITORY = undefined
})

const { toolkit, warningStub } = setup()

process.env.GITHUB_ACTION_REF = 'main'
process.env.GITHUB_REPOSITORY = 'nearform/test-repo'
process.env.GITHUB_ACTION_REPOSITORY = 'nearform/test-repo'
toolkit.logActionRefWarning()

sinon.assert.calledOnceWithMatch(
Expand All @@ -57,14 +57,51 @@ test('should not print warning if actionRef is not main or master', async ({
}) => {
teardown(() => {
process.env.GITHUB_ACTION_REF = undefined
process.env.GITHUB_REPOSITORY = undefined
process.env.GITHUB_ACTION_REPOSITORY = undefined
})

const { toolkit, warningStub } = setup()

process.env.GITHUB_ACTION_REF = 'feat-test'
process.env.GITHUB_REPOSITORY = 'nearform/test-repo'
process.env.GITHUB_ACTION_REPOSITORY = 'nearform/test-repo'
toolkit.logActionRefWarning()

sinon.assert.notCalled(warningStub)
})

test("should print a warning if repoName is not under the 'nearform-actions' organisation", async ({
teardown
}) => {
teardown(() => {
process.env.GITHUB_ACTION_REF = undefined
process.env.GITHUB_ACTION_REPOSITORY = undefined
})

const { toolkit, warningStub } = setup()

process.env.GITHUB_ACTION_REF = 'main'
process.env.GITHUB_ACTION_REPOSITORY = 'nearform/test-repo'
toolkit.logRepoWarning()

sinon.assert.calledOnceWithMatch(
warningStub,
/'nearform' is no longer a valid organisation for this action./
)
})

test("should not print a warning if repoName is under the 'nearform-actions' organisation", async ({
teardown
}) => {
teardown(() => {
process.env.GITHUB_ACTION_REF = undefined
process.env.GITHUB_ACTION_REPOSITORY = undefined
})

const { toolkit, warningStub } = setup()

process.env.GITHUB_ACTION_REF = 'main'
process.env.GITHUB_ACTION_REPOSITORY = 'nearform-actions/test-repo'
toolkit.logRepoWarning()

sinon.assert.notCalled(warningStub)
})

0 comments on commit 51eb375

Please sign in to comment.