Skip to content

Commit

Permalink
Feature/run GitHub workflows (#21)
Browse files Browse the repository at this point in the history
* Added functionality to run a workflow

* Fixed 'show all workflow' script

* Added workflow running functionality via API
  • Loading branch information
Md. Sabbir Alam authored Mar 19, 2021
1 parent 7056907 commit 8936829
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
1 change: 0 additions & 1 deletion src/actions/orgs/option/repos/get_options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ if (options.orgs) {
})
let organizationRepoResponseObject = decodeApiResponse(organizationRepoResponse)
organizationRepoList = organizationRepoResponseObject.response
log(organizationRepoList)
}

export default () => {
Expand Down
2 changes: 1 addition & 1 deletion src/actions/orgs/option/repos/option/workflows/open.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @description Open all workflows
if (options.repos) {
open(options.repos.url + '/actions')
open(options.repos.html_url + '/actions')
} else {
notify('Repository not found', 'error', 3000)
}
28 changes: 28 additions & 0 deletions src/actions/orgs/option/repos/option/workflows/option/run.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// @description Run the workflow
import { accessToken } from '../../../../../../../utils/constants'

if (options.repos) {
let ref = prompt('Please insert the git ref for this action?')
if (!ref) {
ref = 'master'
}

if (options.workflows) {
const url = `${options.workflows.url}/dispatches`
const payload = JSON.stringify({
ref: ref,
})
const header = {
Authorization: 'token ' + accessToken,
}
const response = httpPost(url, payload, header)

if (response.response === '' && response.status === 204) {
notify('Workflow started successfully!', 'success', 3000)
} else {
notify(JSON.stringify(response), 'error', 3000)
}
}
} else {
notify('Repository not found', 'error', 3000)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// @description View the workflow
if (options.repos) {
log(options)
if (options.workflows) {
open(options.workflows.html_url)
}
Expand Down

0 comments on commit 8936829

Please sign in to comment.