Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Commit

Permalink
chore: format body per ADF standards
Browse files Browse the repository at this point in the history
  • Loading branch information
adamk72 committed Mar 16, 2023
1 parent 3e45f3b commit 551b4bd
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 21 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"cSpell.words": [
"Etco",
"issuetype"
]
}
68 changes: 48 additions & 20 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ const { Toolkit } = require('actions-toolkit');
const core = require('@actions/core');
const JiraApi = require('jira-client');

const mdPreamble = "\n\n---\n"

Toolkit.run(async tools => {
try {
const jira = new JiraApi({
protocol: 'https',
host: core.getInput('jiraHost', { required: true }),
username: core.getInput('jiraUsername', { required: true }),
password: core.getInput('jiraPassword', { required: true }),
apiVersion: '2',
apiVersion: '3',
strictSSL: true
});

Expand Down Expand Up @@ -100,44 +98,74 @@ async function addJiraComment(jira, tools) {
async function addJiraTicket(jira, tools) {
const payload = tools.context.payload;
const title = payload.issue.title;
const fullBody = `${payload.issue.body}${mdPreamble}Original post: ${payload.issue.html_url} by ${payload.issue.user.html_url}`;
const footer = `Original post: ${payload.issue.html_url} by ${payload.issue.user.html_url}`;

const project = core.getInput('project', { required: true });

tools.log.pending("Creating Jira ticket with the following parameters");
tools.log.info(`Title: ${title}`);
tools.log.info(`Body: ${fullBody}`);
tools.log.info(`Body: ${payload.issue.body} -- ${footer}`);
tools.log.info(`Project: ${project}`);

let request = {
const request = {
fields: {
project: {
key: project
key: project,
},
summary: title,
description: fullBody,
description: {
content: [
{
type: 'paragraph',
content: [
{
type: 'text',
text: payload.issue.body || "{no content was added to GitHub issue}",
},
],
},
{
type: 'rule',
},
{
type: 'heading',
attrs: {
level: 6,
},
content: [
{
type: 'text',
text: footer,
},
],
},
],
type: 'doc',
version: 1,
},
issuetype: {
name: "Task"
}
}
name: 'Task',
},
},
};

const result = await jira.addNewIssue(request);
tools.log.complete("Created Jira ticket");

const jiraIssue = result.key;
const ghIssueNumber = tools.context.issue.issue_number
tools.log.pending(`Creating issue comment ${ghIssueNumber} with Jira issue number ${jiraIssue}`);
try {
const result = await jira.addNewIssue(request);
tools.log.complete("Created Jira ticket");

const jiraIssue = result.key;
const ghIssueNumber = tools.context.issue.issue_number;
tools.log.pending(`Creating issue comment ${ghIssueNumber} with Jira issue number ${jiraIssue}`);

await tools.github.issues.createComment({
owner: tools.context.repo.owner,
repo: tools.context.repo.repo,
issue_number: ghIssueNumber,
body: `Issue: ${jiraIssue}`
});
return result;

} catch (error) {
tools.log.fatal(error)
tools.exit.failure(`Error on creating Jira ticket ${error}`)
}
tools.log.complete("Created Issue comment with Jira Issue number");
return result;
}
3 changes: 2 additions & 1 deletion package-lock.json

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

0 comments on commit 551b4bd

Please sign in to comment.