Compare commits
No commits in common. "master" and "v3.0.0" have entirely different histories.
@ -1,66 +0,0 @@
|
|||||||
name: Default (not tags)
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
tags-ignore:
|
|
||||||
- '**'
|
|
||||||
|
|
||||||
env:
|
|
||||||
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
|
||||||
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
|
||||||
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
|
||||||
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
|
||||||
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
|
||||||
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
security:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
continue-on-error: true
|
|
||||||
container:
|
|
||||||
image: ${{ env.IMAGE }}
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Install pnpm and npmci
|
|
||||||
run: |
|
|
||||||
pnpm install -g pnpm
|
|
||||||
pnpm install -g @shipzone/npmci
|
|
||||||
|
|
||||||
- name: Run npm prepare
|
|
||||||
run: npmci npm prepare
|
|
||||||
|
|
||||||
- name: Audit production dependencies
|
|
||||||
run: |
|
|
||||||
npmci command npm config set registry https://registry.npmjs.org
|
|
||||||
npmci command pnpm audit --audit-level=high --prod
|
|
||||||
continue-on-error: true
|
|
||||||
|
|
||||||
- name: Audit development dependencies
|
|
||||||
run: |
|
|
||||||
npmci command npm config set registry https://registry.npmjs.org
|
|
||||||
npmci command pnpm audit --audit-level=high --dev
|
|
||||||
continue-on-error: true
|
|
||||||
|
|
||||||
test:
|
|
||||||
if: ${{ always() }}
|
|
||||||
needs: security
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
container:
|
|
||||||
image: ${{ env.IMAGE }}
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Test stable
|
|
||||||
run: |
|
|
||||||
npmci node install stable
|
|
||||||
npmci npm install
|
|
||||||
npmci npm test
|
|
||||||
|
|
||||||
- name: Test build
|
|
||||||
run: |
|
|
||||||
npmci node install stable
|
|
||||||
npmci npm install
|
|
||||||
npmci npm build
|
|
@ -1,124 +0,0 @@
|
|||||||
name: Default (tags)
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
tags:
|
|
||||||
- '*'
|
|
||||||
|
|
||||||
env:
|
|
||||||
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
|
||||||
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
|
||||||
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
|
||||||
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
|
||||||
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
|
||||||
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
security:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
continue-on-error: true
|
|
||||||
container:
|
|
||||||
image: ${{ env.IMAGE }}
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Prepare
|
|
||||||
run: |
|
|
||||||
pnpm install -g pnpm
|
|
||||||
pnpm install -g @shipzone/npmci
|
|
||||||
npmci npm prepare
|
|
||||||
|
|
||||||
- name: Audit production dependencies
|
|
||||||
run: |
|
|
||||||
npmci command npm config set registry https://registry.npmjs.org
|
|
||||||
npmci command pnpm audit --audit-level=high --prod
|
|
||||||
continue-on-error: true
|
|
||||||
|
|
||||||
- name: Audit development dependencies
|
|
||||||
run: |
|
|
||||||
npmci command npm config set registry https://registry.npmjs.org
|
|
||||||
npmci command pnpm audit --audit-level=high --dev
|
|
||||||
continue-on-error: true
|
|
||||||
|
|
||||||
test:
|
|
||||||
if: ${{ always() }}
|
|
||||||
needs: security
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
container:
|
|
||||||
image: ${{ env.IMAGE }}
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Prepare
|
|
||||||
run: |
|
|
||||||
pnpm install -g pnpm
|
|
||||||
pnpm install -g @shipzone/npmci
|
|
||||||
npmci npm prepare
|
|
||||||
|
|
||||||
- name: Test stable
|
|
||||||
run: |
|
|
||||||
npmci node install stable
|
|
||||||
npmci npm install
|
|
||||||
npmci npm test
|
|
||||||
|
|
||||||
- name: Test build
|
|
||||||
run: |
|
|
||||||
npmci node install stable
|
|
||||||
npmci npm install
|
|
||||||
npmci npm build
|
|
||||||
|
|
||||||
release:
|
|
||||||
needs: test
|
|
||||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
container:
|
|
||||||
image: ${{ env.IMAGE }}
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Prepare
|
|
||||||
run: |
|
|
||||||
pnpm install -g pnpm
|
|
||||||
pnpm install -g @shipzone/npmci
|
|
||||||
npmci npm prepare
|
|
||||||
|
|
||||||
- name: Release
|
|
||||||
run: |
|
|
||||||
npmci node install stable
|
|
||||||
npmci npm publish
|
|
||||||
|
|
||||||
metadata:
|
|
||||||
needs: test
|
|
||||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
container:
|
|
||||||
image: ${{ env.IMAGE }}
|
|
||||||
continue-on-error: true
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Prepare
|
|
||||||
run: |
|
|
||||||
pnpm install -g pnpm
|
|
||||||
pnpm install -g @shipzone/npmci
|
|
||||||
npmci npm prepare
|
|
||||||
|
|
||||||
- name: Code quality
|
|
||||||
run: |
|
|
||||||
npmci command npm install -g typescript
|
|
||||||
npmci npm install
|
|
||||||
|
|
||||||
- name: Trigger
|
|
||||||
run: npmci trigger
|
|
||||||
|
|
||||||
- name: Build docs and upload artifacts
|
|
||||||
run: |
|
|
||||||
npmci node install stable
|
|
||||||
npmci npm install
|
|
||||||
pnpm install -g @git.zone/tsdoc
|
|
||||||
npmci command tsdoc
|
|
||||||
continue-on-error: true
|
|
4
.gitignore
vendored
4
.gitignore
vendored
@ -15,6 +15,8 @@ node_modules/
|
|||||||
|
|
||||||
# builds
|
# builds
|
||||||
dist/
|
dist/
|
||||||
dist_*/
|
dist_web/
|
||||||
|
dist_serve/
|
||||||
|
dist_ts_web/
|
||||||
|
|
||||||
# custom
|
# custom
|
119
.gitlab-ci.yml
Normal file
119
.gitlab-ci.yml
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
# gitzone ci_default
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
|
||||||
|
cache:
|
||||||
|
paths:
|
||||||
|
- .npmci_cache/
|
||||||
|
key: "$CI_BUILD_STAGE"
|
||||||
|
|
||||||
|
stages:
|
||||||
|
- security
|
||||||
|
- test
|
||||||
|
- release
|
||||||
|
- metadata
|
||||||
|
|
||||||
|
# ====================
|
||||||
|
# security stage
|
||||||
|
# ====================
|
||||||
|
mirror:
|
||||||
|
stage: security
|
||||||
|
script:
|
||||||
|
- npmci git mirror
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
|
snyk:
|
||||||
|
stage: security
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci command npm install -g snyk
|
||||||
|
- npmci command npm install --ignore-scripts
|
||||||
|
- npmci command snyk test
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
|
# ====================
|
||||||
|
# test stage
|
||||||
|
# ====================
|
||||||
|
|
||||||
|
testStable:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci node install stable
|
||||||
|
- npmci npm install
|
||||||
|
- npmci npm test
|
||||||
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
- priv
|
||||||
|
|
||||||
|
testBuild:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci node install lts
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command npm run build
|
||||||
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
|
release:
|
||||||
|
stage: release
|
||||||
|
script:
|
||||||
|
- npmci node install lts
|
||||||
|
- npmci npm publish
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
|
# ====================
|
||||||
|
# metadata stage
|
||||||
|
# ====================
|
||||||
|
codequality:
|
||||||
|
stage: metadata
|
||||||
|
allow_failure: true
|
||||||
|
script:
|
||||||
|
- npmci command npm install -g tslint typescript
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
- priv
|
||||||
|
|
||||||
|
trigger:
|
||||||
|
stage: metadata
|
||||||
|
script:
|
||||||
|
- npmci trigger
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
|
pages:
|
||||||
|
image: hosttoday/ht-docker-dbase:npmci
|
||||||
|
services:
|
||||||
|
- docker:stable-dind
|
||||||
|
stage: metadata
|
||||||
|
script:
|
||||||
|
- npmci command npm install -g @gitzone/tsdoc
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command tsdoc
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
- notpriv
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
|
artifacts:
|
||||||
|
expire_in: 1 week
|
||||||
|
paths:
|
||||||
|
- public
|
||||||
|
allow_failure: true
|
24
.vscode/launch.json
vendored
24
.vscode/launch.json
vendored
@ -2,10 +2,28 @@
|
|||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"command": "npm test",
|
"name": "current file",
|
||||||
"name": "Run npm test",
|
"type": "node",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"type": "node-terminal"
|
"args": [
|
||||||
|
"${relativeFile}"
|
||||||
|
],
|
||||||
|
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||||
|
"cwd": "${workspaceRoot}",
|
||||||
|
"protocol": "inspector",
|
||||||
|
"internalConsoleOptions": "openOnSessionStart"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "test.ts",
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"args": [
|
||||||
|
"test/test.ts"
|
||||||
|
],
|
||||||
|
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||||
|
"cwd": "${workspaceRoot}",
|
||||||
|
"protocol": "inspector",
|
||||||
|
"internalConsoleOptions": "openOnSessionStart"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
27
.vscode/settings.json
vendored
27
.vscode/settings.json
vendored
@ -1,27 +0,0 @@
|
|||||||
{
|
|
||||||
"json.schemas": [
|
|
||||||
{
|
|
||||||
"fileMatch": ["/npmextra.json"],
|
|
||||||
"schema": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"npmci": {
|
|
||||||
"type": "object",
|
|
||||||
"description": "settings for npmci"
|
|
||||||
},
|
|
||||||
"gitzone": {
|
|
||||||
"type": "object",
|
|
||||||
"description": "settings for gitzone",
|
|
||||||
"properties": {
|
|
||||||
"projectType": {
|
|
||||||
"type": "string",
|
|
||||||
"enum": ["website", "element", "service", "npm", "wcc"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"typescript.tsdk": "node_modules/typescript/lib"
|
|
||||||
}
|
|
@ -4,13 +4,12 @@
|
|||||||
"npmAccessLevel": "public"
|
"npmAccessLevel": "public"
|
||||||
},
|
},
|
||||||
"gitzone": {
|
"gitzone": {
|
||||||
"projectType": "npm",
|
|
||||||
"module": {
|
"module": {
|
||||||
"githost": "gitlab.com",
|
"githost": "gitlab.com",
|
||||||
"gitscope": "apiclient.xyz",
|
"gitscope": "mojoio",
|
||||||
"gitrepo": "slack",
|
"gitrepo": "slack",
|
||||||
"description": "slack api abstraction for the mojo.io ecosystem",
|
"shortDescription": "slack api abstraction for the mojo.io ecosystem",
|
||||||
"npmPackagename": "@apiclient.xyz/slack",
|
"npmPackagename": "@mojoio/slack",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1583
package-lock.json
generated
Normal file
1583
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
50
package.json
50
package.json
@ -1,48 +1,36 @@
|
|||||||
{
|
{
|
||||||
"name": "@apiclient.xyz/slack",
|
"name": "@mojoio/slack",
|
||||||
"version": "3.0.9",
|
"version": "3.0.0",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "slack api abstraction for the mojo.io ecosystem",
|
"description": "slack api abstraction for the mojo.io ecosystem",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist/index.js",
|
||||||
"typings": "dist_ts/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
"author": "Lossless GmbH",
|
"author": "Lossless GmbH",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "tstest test/",
|
"test": "tstest test/",
|
||||||
"build": "tsbuild --web"
|
"build": "tsbuild"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@git.zone/tsbuild": "^2.1.25",
|
"@gitzone/tsbuild": "^2.1.17",
|
||||||
"@git.zone/tsrun": "^1.2.17",
|
"@gitzone/tsrun": "^1.2.8",
|
||||||
"@git.zone/tstest": "^1.0.54",
|
"@gitzone/tstest": "^1.0.24",
|
||||||
"@push.rocks/qenv": "^6.0.4",
|
"@pushrocks/qenv": "^4.0.4",
|
||||||
"@push.rocks/tapbundle": "^5.0.15",
|
"@pushrocks/tapbundle": "^3.0.13",
|
||||||
"@types/node": "^20.11.6",
|
"@types/node": "^12.7.4"
|
||||||
"typescript": "^5.3.3"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@push.rocks/smartpromise": "^4.0.3",
|
"@pushrocks/smartrequest": "^1.1.23"
|
||||||
"@push.rocks/smartrequest": "^2.0.21"
|
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/**/*",
|
"ts/*",
|
||||||
"ts_web/**/*",
|
"ts_web/*",
|
||||||
"dist/**/*",
|
"dist/*",
|
||||||
"dist_*/**/*",
|
"dist_web/*",
|
||||||
"dist_ts/**/*",
|
"dist_ts_web/*",
|
||||||
"dist_ts_web/**/*",
|
"assets/*",
|
||||||
"assets/**/*",
|
|
||||||
"cli.js",
|
"cli.js",
|
||||||
"npmextra.json",
|
"npmextra.json",
|
||||||
"readme.md"
|
"readme.md"
|
||||||
],
|
]
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git+https://gitlab.com/apiclient.xyz/slack.git"
|
|
||||||
},
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://gitlab.com/apiclient.xyz/slack/issues"
|
|
||||||
},
|
|
||||||
"homepage": "https://gitlab.com/apiclient.xyz/slack#readme",
|
|
||||||
"type": "module"
|
|
||||||
}
|
}
|
||||||
|
5711
pnpm-lock.yaml
generated
5711
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
117
test/test.ts
117
test/test.ts
@ -1,45 +1,19 @@
|
|||||||
import { expect, tap } from '@push.rocks/tapbundle';
|
import { expect, tap } from '@pushrocks/tapbundle';
|
||||||
import { Qenv } from '@push.rocks/qenv';
|
import { Qenv } from '@pushrocks/qenv';
|
||||||
|
|
||||||
let testQenv = new Qenv(process.cwd(), process.cwd() + '/.nogit');
|
let testQenv = new Qenv(process.cwd(), process.cwd() + '/.nogit');
|
||||||
|
|
||||||
import * as slackme from '../ts/index.js';
|
import * as slackme from '../ts/index';
|
||||||
|
|
||||||
let testSlackAccount: slackme.SlackAccount;
|
let testSlackme: slackme.SlackAccount;
|
||||||
let testSlackMessage: slackme.SlackMessage;
|
let testSlackMessage: slackme.SlackMessage;
|
||||||
|
|
||||||
tap.test('should create a valid slackme instance', async tools => {
|
tap.test('should create a valid slackme instance', async (tools) => {
|
||||||
testSlackAccount = new slackme.SlackAccount(await testQenv.getEnvVarOnDemand('SLACK_TOKEN'));
|
testSlackme = new slackme.SlackAccount(testQenv.getEnvVarOnDemand('SLACK_TOKEN'));
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should send a message to Slack', async tools => {
|
tap.test('should send a message to Slack', async (tools) => {
|
||||||
const messageOptions = {
|
testSlackMessage = new slackme.SlackMessage({
|
||||||
author_name: 'GitLab CI',
|
|
||||||
author_link: 'https://gitlab.com/',
|
|
||||||
pretext: '*Good News*: Build successfull!',
|
|
||||||
color: '#3cb371',
|
|
||||||
fields: [
|
|
||||||
{
|
|
||||||
title: 'Branch',
|
|
||||||
value: 'Lossless Cloud',
|
|
||||||
short: true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: 'Product ID',
|
|
||||||
value: 'pushrocks',
|
|
||||||
short: true
|
|
||||||
}
|
|
||||||
]
|
|
||||||
};
|
|
||||||
await testSlackAccount.sendMessage({
|
|
||||||
channelArg: 'random',
|
|
||||||
messageOptions: messageOptions,
|
|
||||||
mode: 'new'
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
tap.test('should send a message to Slack by directly calling the message', async tools => {
|
|
||||||
testSlackMessage = new slackme.SlackMessage(testSlackAccount, {
|
|
||||||
author_name: 'GitLab CI',
|
author_name: 'GitLab CI',
|
||||||
author_link: 'https://gitlab.com/',
|
author_link: 'https://gitlab.com/',
|
||||||
pretext: '*Good News*: Build successfull!',
|
pretext: '*Good News*: Build successfull!',
|
||||||
@ -57,6 +31,31 @@ tap.test('should send a message to Slack by directly calling the message', async
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
await testSlackme.sendMessage(testSlackMessage.messageOptions, 'random');
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should send a message to Slack by directly calling the message', async (tools) => {
|
||||||
|
testSlackMessage = new slackme.SlackMessage(
|
||||||
|
{
|
||||||
|
author_name: 'GitLab CI',
|
||||||
|
author_link: 'https://gitlab.com/',
|
||||||
|
pretext: '*Good News*: Build successfull!',
|
||||||
|
color: '#3cb371',
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
title: 'Branch',
|
||||||
|
value: 'Lossless Cloud',
|
||||||
|
short: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Product ID',
|
||||||
|
value: 'pushrocks',
|
||||||
|
short: true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
testSlackme
|
||||||
|
);
|
||||||
await testSlackMessage.sendToRoom('random');
|
await testSlackMessage.sendToRoom('random');
|
||||||
await tools.delayFor(1000);
|
await tools.delayFor(1000);
|
||||||
await testSlackMessage.updateAndSend({
|
await testSlackMessage.updateAndSend({
|
||||||
@ -76,55 +75,7 @@ tap.test('should send a message to Slack by directly calling the message', async
|
|||||||
short: true
|
short: true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
})
|
||||||
await testSlackMessage.updateAndSend({
|
|
||||||
author_name: 'GitLab CI',
|
|
||||||
author_link: 'https://gitlab.com/',
|
|
||||||
pretext: '*Good News*: Build successfull!',
|
|
||||||
color: '#3cb371',
|
|
||||||
fields: [
|
|
||||||
{
|
|
||||||
title: 'Branch',
|
|
||||||
value: 'Lossless Studio',
|
|
||||||
short: true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: 'Product ID',
|
|
||||||
value: 'onboard.me',
|
|
||||||
short: true
|
|
||||||
}
|
|
||||||
]
|
|
||||||
});
|
|
||||||
await testSlackMessage.startThread({
|
|
||||||
author_name: 'Lossless Compliance',
|
|
||||||
author_link: 'https://gitlab.com/',
|
|
||||||
pretext: '*Good News*: Build successfull!',
|
|
||||||
color: '#3cb371',
|
|
||||||
fields: [
|
|
||||||
{
|
|
||||||
title: 'Branch',
|
|
||||||
value: 'Lossless Studio',
|
|
||||||
short: true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: 'Product ID',
|
|
||||||
value: 'pushrocks',
|
|
||||||
short: true
|
|
||||||
}
|
|
||||||
]
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
tap.test('should send logs', async () => {
|
|
||||||
const slackLog = new slackme.SlackLog({
|
|
||||||
slackAccount: testSlackAccount,
|
|
||||||
channelName: 'random'
|
|
||||||
});
|
|
||||||
for (let i = 0; i < 30; i++) {
|
|
||||||
await slackLog.sendLogLine('hi there');
|
|
||||||
await slackLog.sendLogLine('so awesome');
|
|
||||||
await slackLog.sendLogLine('really');
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
/**
|
|
||||||
* autocreated commitinfo by @pushrocks/commitinfo
|
|
||||||
*/
|
|
||||||
export const commitinfo = {
|
|
||||||
name: '@apiclient.xyz/slack',
|
|
||||||
version: '3.0.9',
|
|
||||||
description: 'slack api abstraction for the mojo.io ecosystem'
|
|
||||||
}
|
|
@ -1,63 +0,0 @@
|
|||||||
import * as plugins from './plugins.js';
|
|
||||||
import { type IMessageOptions } from './classes.slackmessage.js';
|
|
||||||
|
|
||||||
export class SlackAccount {
|
|
||||||
private postUrl = 'https://slack.com/api/chat.postMessage';
|
|
||||||
private updateUrl = 'https://slack.com/api/chat.update';
|
|
||||||
private slackToken: string;
|
|
||||||
constructor(slackTokenArg: string) {
|
|
||||||
this.slackToken = slackTokenArg;
|
|
||||||
}
|
|
||||||
|
|
||||||
async sendMessage(optionsArg: {
|
|
||||||
messageOptions: IMessageOptions;
|
|
||||||
channelArg: string;
|
|
||||||
ts?: string;
|
|
||||||
mode: 'new' | 'threaded' | 'update';
|
|
||||||
}) {
|
|
||||||
let requestBody: any = {
|
|
||||||
channel: optionsArg.channelArg,
|
|
||||||
text: optionsArg.messageOptions.text
|
|
||||||
};
|
|
||||||
|
|
||||||
if (optionsArg.messageOptions.fields) {
|
|
||||||
requestBody = {
|
|
||||||
...requestBody,
|
|
||||||
attachments: [
|
|
||||||
{
|
|
||||||
pretext: optionsArg.messageOptions.pretext,
|
|
||||||
fields: optionsArg.messageOptions.fields,
|
|
||||||
ts: optionsArg.messageOptions.ts,
|
|
||||||
color: optionsArg.messageOptions.color
|
|
||||||
}
|
|
||||||
]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
let postUrl = this.postUrl;
|
|
||||||
|
|
||||||
switch (true) {
|
|
||||||
case optionsArg.ts && optionsArg.mode === 'update':
|
|
||||||
requestBody = {
|
|
||||||
...requestBody,
|
|
||||||
ts: optionsArg.ts
|
|
||||||
};
|
|
||||||
postUrl = this.updateUrl;
|
|
||||||
break;
|
|
||||||
case optionsArg.ts && optionsArg.mode === 'threaded':
|
|
||||||
requestBody = {
|
|
||||||
...requestBody,
|
|
||||||
thread_ts: optionsArg.ts
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await plugins.smartrequest.postJson(postUrl, {
|
|
||||||
headers: {
|
|
||||||
Authorization: `Bearer ${this.slackToken}`
|
|
||||||
},
|
|
||||||
requestBody
|
|
||||||
});
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
import { SlackAccount } from './classes.slackaccount.js';
|
|
||||||
import { SlackMessage } from './classes.slackmessage.js';
|
|
||||||
|
|
||||||
export class SlackLog {
|
|
||||||
public slackAccount: SlackAccount;
|
|
||||||
public slackMessage: SlackMessage;
|
|
||||||
public channelName: string;
|
|
||||||
|
|
||||||
public completeLog = ``;
|
|
||||||
|
|
||||||
constructor(optionsArg: { slackAccount: SlackAccount; channelName: string }) {
|
|
||||||
this.slackAccount = optionsArg.slackAccount;
|
|
||||||
this.channelName = optionsArg.channelName;
|
|
||||||
}
|
|
||||||
public async sendLogLine(logText: string) {
|
|
||||||
if (!this.slackMessage) {
|
|
||||||
this.slackMessage = new SlackMessage(this.slackAccount, {
|
|
||||||
text: '``` log is loading... ```'
|
|
||||||
});
|
|
||||||
await this.slackMessage.sendToRoom(this.channelName);
|
|
||||||
}
|
|
||||||
const date = new Date();
|
|
||||||
this.completeLog +=
|
|
||||||
`${date.getHours()}:${date.getMinutes()}:${date.getSeconds()} - ` + logText + '\n';
|
|
||||||
await this.slackMessage.updateAndSend({
|
|
||||||
text: '```\n' + this.completeLog + '\n```'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,98 +0,0 @@
|
|||||||
import * as plugins from './plugins.js';
|
|
||||||
import { SlackAccount } from './classes.slackaccount.js';
|
|
||||||
|
|
||||||
export interface IAttachmentField {
|
|
||||||
title: string;
|
|
||||||
value: string;
|
|
||||||
short?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IMessageOptions {
|
|
||||||
/**
|
|
||||||
* "Required plain-text summary of the attachment."
|
|
||||||
*/
|
|
||||||
fallback?: string;
|
|
||||||
/**
|
|
||||||
* a side color
|
|
||||||
*/
|
|
||||||
color?: string;
|
|
||||||
/**
|
|
||||||
* a message to show above
|
|
||||||
*/
|
|
||||||
pretext?: string;
|
|
||||||
/**
|
|
||||||
* author name of the attachment
|
|
||||||
*/
|
|
||||||
author_name?: string;
|
|
||||||
/**
|
|
||||||
* a link to the author
|
|
||||||
*/
|
|
||||||
author_link?: string;
|
|
||||||
/**
|
|
||||||
* a string to the author
|
|
||||||
*/
|
|
||||||
author_icon?: string;
|
|
||||||
/**
|
|
||||||
* a title for the attachment
|
|
||||||
*/
|
|
||||||
title?: string;
|
|
||||||
/**
|
|
||||||
* a link for the title
|
|
||||||
*/
|
|
||||||
title_link?: string;
|
|
||||||
/**
|
|
||||||
* the main text of the message
|
|
||||||
*/
|
|
||||||
text?: string;
|
|
||||||
fields?: IAttachmentField[];
|
|
||||||
image_url?: string;
|
|
||||||
thumb_url?: string;
|
|
||||||
footer?: string;
|
|
||||||
footer_icon?: string;
|
|
||||||
ts?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class SlackMessage {
|
|
||||||
public slackAccountRef: SlackAccount;
|
|
||||||
public messageOptions: IMessageOptions;
|
|
||||||
public channel: string;
|
|
||||||
public ts: string;
|
|
||||||
|
|
||||||
public requestRunning = plugins.smartpromise.defer();
|
|
||||||
|
|
||||||
constructor(slackAccountArg: SlackAccount, messageOptionsArg: IMessageOptions) {
|
|
||||||
if (slackAccountArg) {
|
|
||||||
this.slackAccountRef = slackAccountArg;
|
|
||||||
}
|
|
||||||
this.messageOptions = messageOptionsArg;
|
|
||||||
this.requestRunning.resolve();
|
|
||||||
}
|
|
||||||
|
|
||||||
async updateAndSend(messageOptionsArg: IMessageOptions) {
|
|
||||||
this.messageOptions = messageOptionsArg;
|
|
||||||
await this.sendToRoom(this.channel, 'update');
|
|
||||||
}
|
|
||||||
|
|
||||||
async startThread(messageOptionsArg: IMessageOptions) {
|
|
||||||
this.messageOptions = messageOptionsArg;
|
|
||||||
this.sendToRoom(this.channel, 'threaded');
|
|
||||||
}
|
|
||||||
|
|
||||||
async sendToRoom(channelNameArg: string, modeArg: 'new' | 'update' | 'threaded' = 'new') {
|
|
||||||
this.channel = channelNameArg;
|
|
||||||
if (this.slackAccountRef) {
|
|
||||||
const response = await this.slackAccountRef.sendMessage({
|
|
||||||
channelArg: this.channel,
|
|
||||||
messageOptions: this.messageOptions,
|
|
||||||
mode: modeArg,
|
|
||||||
ts: this.ts
|
|
||||||
});
|
|
||||||
if (modeArg === 'new') {
|
|
||||||
this.ts = response.body.message.ts;
|
|
||||||
this.channel = response.body.channel;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new Error('you need to set a slackRef before sending the message!');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,3 +1,2 @@
|
|||||||
export * from './classes.slackaccount.js';
|
export * from './slack.classes.slackme';
|
||||||
export * from './classes.slackmessage.js';
|
export * from './slack.classes.slackmessage';
|
||||||
export * from './classes.slacklog.js';
|
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
// pushrocks scope
|
|
||||||
import * as smartpromise from '@push.rocks/smartpromise';
|
|
||||||
import * as smartrequest from '@push.rocks/smartrequest';
|
|
||||||
|
|
||||||
export { smartpromise, smartrequest };
|
|
33
ts/slack.classes.slackme.ts
Normal file
33
ts/slack.classes.slackme.ts
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import * as plugins from './slack.plugins';
|
||||||
|
import { IMessageOptions } from './slack.classes.slackmessage';
|
||||||
|
|
||||||
|
export class SlackAccount {
|
||||||
|
private postUrl = 'https://slack.com/api/chat.postMessage';
|
||||||
|
private updateUrl = 'https://slack.com/api/chat.update';
|
||||||
|
private slackToken: string;
|
||||||
|
constructor(slackTokenArg: string) {
|
||||||
|
this.slackToken = slackTokenArg;
|
||||||
|
}
|
||||||
|
|
||||||
|
async sendMessage(messageOptionsArg: IMessageOptions, channelArg: string = 'status', tsArg?: string) {
|
||||||
|
let requestBody: any = {
|
||||||
|
channel: channelArg,
|
||||||
|
attachments: [messageOptionsArg]
|
||||||
|
}
|
||||||
|
let postUrl = this.postUrl;
|
||||||
|
if (tsArg) {
|
||||||
|
requestBody = {
|
||||||
|
...requestBody,
|
||||||
|
ts: tsArg
|
||||||
|
}
|
||||||
|
postUrl = this.updateUrl;
|
||||||
|
}
|
||||||
|
const response = await plugins.smartrequest.postJson(postUrl, {
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${this.slackToken}`
|
||||||
|
},
|
||||||
|
requestBody
|
||||||
|
});
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
}
|
82
ts/slack.classes.slackmessage.ts
Normal file
82
ts/slack.classes.slackmessage.ts
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
import * as plugins from './slack.plugins';
|
||||||
|
import { SlackAccount } from './slack.classes.slackme';
|
||||||
|
|
||||||
|
export interface IAttachmentField {
|
||||||
|
title: string;
|
||||||
|
value: string;
|
||||||
|
short?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IMessageOptions {
|
||||||
|
/**
|
||||||
|
* "Required plain-text summary of the attachment."
|
||||||
|
*/
|
||||||
|
fallback?: string;
|
||||||
|
/**
|
||||||
|
* a side color
|
||||||
|
*/
|
||||||
|
color?: string;
|
||||||
|
/**
|
||||||
|
* a message to show above
|
||||||
|
*/
|
||||||
|
pretext?: string;
|
||||||
|
/**
|
||||||
|
* author name of the attachment
|
||||||
|
*/
|
||||||
|
author_name?: string;
|
||||||
|
/**
|
||||||
|
* a link to the author
|
||||||
|
*/
|
||||||
|
author_link?: string;
|
||||||
|
/**
|
||||||
|
* a string to the author
|
||||||
|
*/
|
||||||
|
author_icon?: string;
|
||||||
|
/**
|
||||||
|
* a title for the attachment
|
||||||
|
*/
|
||||||
|
title?: string;
|
||||||
|
/**
|
||||||
|
* a link for the title
|
||||||
|
*/
|
||||||
|
title_link?: string;
|
||||||
|
/**
|
||||||
|
* the main text of the message
|
||||||
|
*/
|
||||||
|
text?: string;
|
||||||
|
fields?: IAttachmentField[];
|
||||||
|
image_url?: string;
|
||||||
|
thumb_url?: string;
|
||||||
|
footer?: string;
|
||||||
|
footer_icon?: string;
|
||||||
|
ts?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class SlackMessage {
|
||||||
|
slackmeRef: SlackAccount;
|
||||||
|
messageOptions: IMessageOptions;
|
||||||
|
channel: string;
|
||||||
|
ts: string;
|
||||||
|
constructor(messageOptionsArg: IMessageOptions, slackmeArg?: SlackAccount) {
|
||||||
|
if (slackmeArg) {
|
||||||
|
this.slackmeRef = slackmeArg;
|
||||||
|
}
|
||||||
|
this.messageOptions = messageOptionsArg;
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateAndSend(messageOptionsArg: IMessageOptions) {
|
||||||
|
this.messageOptions = messageOptionsArg;
|
||||||
|
await this.sendToRoom(this.channel);
|
||||||
|
}
|
||||||
|
|
||||||
|
async sendToRoom(roomNameArg: string) {
|
||||||
|
this.channel = roomNameArg;
|
||||||
|
if (this.slackmeRef) {
|
||||||
|
const response = await this.slackmeRef.sendMessage(this.messageOptions, roomNameArg, this.ts);
|
||||||
|
this.ts = response.body.message.ts;
|
||||||
|
this.channel = response.body.channel;
|
||||||
|
} else {
|
||||||
|
throw new Error('you need to set a slackRef before sending the message!');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
4
ts/slack.plugins.ts
Normal file
4
ts/slack.plugins.ts
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
// pushrocks scope
|
||||||
|
import * as smartrequest from '@pushrocks/smartrequest';
|
||||||
|
|
||||||
|
export { smartrequest };
|
@ -1,14 +0,0 @@
|
|||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"experimentalDecorators": true,
|
|
||||||
"useDefineForClassFields": false,
|
|
||||||
"target": "ES2022",
|
|
||||||
"module": "NodeNext",
|
|
||||||
"moduleResolution": "NodeNext",
|
|
||||||
"esModuleInterop": true,
|
|
||||||
"verbatimModuleSyntax": true
|
|
||||||
},
|
|
||||||
"exclude": [
|
|
||||||
"dist_*/**/*.d.ts"
|
|
||||||
]
|
|
||||||
}
|
|
17
tslint.json
Normal file
17
tslint.json
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"extends": ["tslint:latest", "tslint-config-prettier"],
|
||||||
|
"rules": {
|
||||||
|
"semicolon": [true, "always"],
|
||||||
|
"no-console": false,
|
||||||
|
"ordered-imports": false,
|
||||||
|
"object-literal-sort-keys": false,
|
||||||
|
"member-ordering": {
|
||||||
|
"options":{
|
||||||
|
"order": [
|
||||||
|
"static-method"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"defaultSeverity": "warning"
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user