Skip to content

Commit

Permalink
chore(dependencies): downgraded required node version from 18 to 16
Browse files Browse the repository at this point in the history
+ added node-fetch as fetch is not activated by default in node 16
  • Loading branch information
yllieth committed Aug 6, 2022
1 parent 70fe24b commit 251612f
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 30 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
node-version: 16
- run: npm ci
- run: npm test

Expand All @@ -19,7 +19,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
node-version: 16
- run: npm ci
- run: npm run lint

Expand All @@ -31,7 +31,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
node-version: 16
- run: npm ci
- run: npm run release -- --dry-run
env:
Expand All @@ -47,7 +47,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
node-version: 16
- run: npm ci
- run: npm run release
env:
Expand Down
15 changes: 1 addition & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ yarn add semantic-release-ms-teams --dev
This plugin is using an _incoming webhook_ to notify a teams channel. Here is
[some documentation](https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook#add-an-incoming-webhook-to-a-teams-channel) to create one.

Also note that this package requires node 18 for the following 2 reasons:
- the upgrade to semantic-release 19 as a peerDependency caused the requirement of node 16
- the use of the native version of fetchAPI requires node 18

## Usage

```json
Expand Down Expand Up @@ -58,6 +54,7 @@ Also note that this package requires node 18 for the following 2 reasons:
prefers environment variables. You can use both, but not in the same time as
it does not make sense. If you do define both, the config object overrides
the environment variable.
-
- **IMPORTANT**: The `webhookUrl` variable you can use within your plugin
configuration is meant to be used only for test purposes. Because you don't
want to publicly publish this url and do let the world know a way to send
Expand All @@ -71,9 +68,6 @@ Also note that this package requires node 18 for the following 2 reasons:
(only the part before the "@" is kept). This list can be disable (mainly for
privacy reasons).

- The message is sent to Teams during the `success` step which is silenced in
`dryRun` mode.

- The official `@semantic-release/git` plugin may cause a second message to be
sent (because the plugin potentially adds a commit on the current branch, to
save changes in files like `package.json`, `package-lock.json`, `CHANGELOG.md`).
Expand All @@ -96,13 +90,6 @@ Here are some steps to test the plugin locally:
cd semantic-release-ms-teams
npm install
```
- add a `.releaserc.json` file at the project's root, copy the code from the
[Usage](#usage) section in this new file using the `webhookUrl` property, and
add the following properties in the object:
```
"ci": false,
"dryRun": true,
```
- create a personal access token in github, then `export GH_TOKEN=...`
- run `semantic-release` locally safely:
```sh
Expand Down
13 changes: 8 additions & 5 deletions __tests__/lib/lifecycle-success.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
const lifecycleSuccess = require('../../lib/lifecycle-success')

const fetch = require('node-fetch-commonjs')
jest.mock('node-fetch-commonjs')

const teamsify = require('../../lib/teamsify')
jest.mock('../../lib/teamsify')

Expand Down Expand Up @@ -28,7 +31,7 @@ describe('lifecycleSuccess', () => {
const teamsNotification = { foo: 'bar' }
pluginConfig.webhookUrl = url
context.options.dryRun = false
global.fetch = jest.fn(() => Promise.resolve())
fetch.mockImplementation(() => Promise.resolve())
teamsify.mockImplementation(() => teamsNotification)

// act
Expand All @@ -51,7 +54,7 @@ describe('lifecycleSuccess', () => {
const teamsNotification = { foo: 'bar' }
context.env.TEAMS_WEBHOOK_URL = url
context.options.dryRun = false
global.fetch = jest.fn(() => Promise.resolve())
fetch.mockImplementation(() => Promise.resolve())
teamsify.mockImplementation(() => teamsNotification)

// act
Expand All @@ -74,7 +77,7 @@ describe('lifecycleSuccess', () => {
pluginConfig.webhookUrl = 'http://example-a.com'
context.env.TEAMS_WEBHOOK_URL = 'http://example-b.com'
context.options.dryRun = false
global.fetch = jest.fn(() => Promise.resolve())
fetch.mockImplementation(() => Promise.resolve())
teamsify.mockImplementation(() => teamsNotification)

// act
Expand All @@ -93,7 +96,7 @@ describe('lifecycleSuccess', () => {
context.env.TEAMS_WEBHOOK_URL = 'http://example.com'
context.options.dryRun = true
pluginConfig.notifyInDryRun = true
global.fetch = jest.fn(() => Promise.resolve())
fetch.mockImplementation(() => Promise.resolve())
teamsify.mockImplementation(() => {
throw 'teamsify error'
})
Expand All @@ -114,7 +117,7 @@ describe('lifecycleSuccess', () => {
const teamsNotification = { foo: 'bar' }
context.env.TEAMS_WEBHOOK_URL = url
context.options.dryRun = false
global.fetch = jest.fn(() => Promise.reject('Failed to fetch'))
fetch.mockImplementation(() => Promise.reject('Failed to fetch'))
teamsify.mockImplementation(() => teamsNotification)

// act
Expand Down
3 changes: 2 additions & 1 deletion lib/lifecycle-success.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const nodeFetch = require('node-fetch-commonjs').default
const teamsify = require('./teamsify')

module.exports = async (pluginConfig, context) => {
Expand All @@ -19,7 +20,7 @@ module.exports = async (pluginConfig, context) => {
}

if (!teamsifyError) {
fetch(url, { method: 'post', body, headers })
nodeFetch(url, { method: 'post', body, headers })
.then(() => logger.log('Message sent to Microsoft Teams'))
.catch((error) => logger.error('An error occurred while sending the message to Teams', error))
.finally(() => {
Expand Down
118 changes: 115 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@
"package-lock.json"
],
"engines": {
"node": ">=18",
"npm": ">7",
"yarn": ">2"
"node": ">=16",
"npm": ">=8",
"yarn": ">=2"
},
"dependencies": {
"mdast-util-to-markdown": "^1.3.0",
"node-fetch-commonjs": "^3.1.1",
"remark": "^14.0.2"
},
"devDependencies": {
Expand Down

0 comments on commit 251612f

Please sign in to comment.