Skip to content

Commit

Permalink
initial commit of github action
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzaloaune committed Jan 27, 2024
1 parent cefdb28 commit 22816f2
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 154 deletions.
2 changes: 1 addition & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Repository CODEOWNERS

* @actions/actions-oss-maintainers
* @stakwork
96 changes: 0 additions & 96 deletions __tests__/main.test.js

This file was deleted.

24 changes: 0 additions & 24 deletions __tests__/wait.test.js

This file was deleted.

27 changes: 19 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
name: 'The name of your action here'
description: 'Provide a description here'
author: 'Your name or organization here'
name: 'Sphixn Bot'
description: 'Sphinx Bot Github Action'
author: 'Stakwork & Sphinx'

# Define your inputs here.
inputs:
milliseconds:
description: 'Your input description here'
tribe_url:
description: 'URL of the tribe you want to post to'
required: true
bot_id:
description: 'BOT ID of the tribe you want to post to'
required: true
bot_secret:
description: 'BOT Secret of the tribe you want to post to'
required: true
chat_uuid:
description: 'Chat UUID of the tribe you want to post to'
required: true
bot_message:
description: 'Message to post'
required: true
default: '1000'

# Define your outputs here.
outputs:
time:
description: 'Your output description here'
response:
description: 'Response from the bot'

runs:
using: node20
Expand Down
25 changes: 17 additions & 8 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
const core = require('@actions/core')
const { wait } = require('./wait')
const { http_client } = require('@actions/http-client')

/**
* The main function for the action.
* @returns {Promise<void>} Resolves when the action is complete.
*/
async function run() {
try {
const ms = core.getInput('milliseconds', { required: true })
const tribe_url = core.getInput('tribe_url', { required: true })
const bot_id = core.getInput('bot_id', { required: true })
const bot_secret = core.getInput('bot_secret', { required: true })
const chat_uuid = core.getInput('chat_uuid', { required: true })
const bot_message = core.getInput('bot_message', { required: true })

// Debug logs are only output if the `ACTIONS_STEP_DEBUG` secret is true
core.debug(`Waiting ${ms} milliseconds ...`)
core.debug(`Posting to ${tribe_url} ...`)

// Log the current timestamp, wait, then log the new timestamp
core.debug(new Date().toTimeString())
await wait(parseInt(ms, 10))
core.debug(new Date().toTimeString())
const req_params = {
action: 'broadcast',
bot_id: bot_id,

Check failure on line 21 in src/main.js

View workflow job for this annotation

GitHub Actions / Lint Codebase

Expected property shorthand

Check failure on line 21 in src/main.js

View workflow job for this annotation

GitHub Actions / JavaScript Tests

Expected property shorthand
bot_secret: bot_secret,

Check failure on line 22 in src/main.js

View workflow job for this annotation

GitHub Actions / Lint Codebase

Expected property shorthand

Check failure on line 22 in src/main.js

View workflow job for this annotation

GitHub Actions / JavaScript Tests

Expected property shorthand
chat_uuid: chat_uuid,

Check failure on line 23 in src/main.js

View workflow job for this annotation

GitHub Actions / Lint Codebase

Expected property shorthand

Check failure on line 23 in src/main.js

View workflow job for this annotation

GitHub Actions / JavaScript Tests

Expected property shorthand
content: bot_message
}

const restRes = await http_client.postJson(tribe_url, req_params)

// Set outputs for other workflow steps to use
core.setOutput('time', new Date().toTimeString())
core.setOutput('response', restRes.result.json)
} catch (error) {
// Fail the workflow run if an error occurs
core.setFailed(error.message)
Expand Down
17 changes: 0 additions & 17 deletions src/wait.js

This file was deleted.

0 comments on commit 22816f2

Please sign in to comment.