From 5761cb26cd859243f33ae44b3e289f68e6e016d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Altrui?= Date: Thu, 18 Feb 2021 00:20:14 -0300 Subject: [PATCH 1/5] feat: added jira api and add message service --- package.json | 1 + src/config/firebase.ts | 3 --- src/config/jiraAPI.ts | 12 ++++++++++++ src/handlers/jira/index.ts | 14 ++++++++++++++ src/index.ts | 4 ++++ src/probotApp/handlers/released.ts | 6 ++++++ src/probotApp/index.ts | 3 +++ yarn.lock | 13 +++++++++++++ 8 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 src/config/jiraAPI.ts create mode 100644 src/handlers/jira/index.ts create mode 100644 src/probotApp/handlers/released.ts diff --git a/package.json b/package.json index 3524fab..68e6258 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "@octokit/core": "^3.2.5", "@slack/events-api": "^2.3.0", "@slack/web-api": "^5.1.0", + "apisauce": "^2.0.1", "apollo-link": "^1.2.12", "apollo-link-http": "^1.5.15", "body-parser": "^1.19.0", diff --git a/src/config/firebase.ts b/src/config/firebase.ts index 9e8043f..102b822 100644 --- a/src/config/firebase.ts +++ b/src/config/firebase.ts @@ -1,9 +1,6 @@ import admin from 'firebase-admin'; -import dotenv from 'dotenv'; import { Config } from 'firebase'; -dotenv.config(); - const serviceAccount: Config = { type: 'service_account', project_id: process.env.FIRESTORE_PROYECT_ID || 'aaa', diff --git a/src/config/jiraAPI.ts b/src/config/jiraAPI.ts new file mode 100644 index 0000000..dae49e0 --- /dev/null +++ b/src/config/jiraAPI.ts @@ -0,0 +1,12 @@ +import { create } from 'apisauce'; + +const api = create({ + baseURL: 'https://widergy.atlassian.net/rest/api/3', + headers: { + Authorization: `Basic ${process.env.JIRA_AUTH_TOKEN}`, + 'Content-Type': 'application/json', + Accept: 'application/json', + }, +}); + +export default api; diff --git a/src/handlers/jira/index.ts b/src/handlers/jira/index.ts new file mode 100644 index 0000000..09b4cc6 --- /dev/null +++ b/src/handlers/jira/index.ts @@ -0,0 +1,14 @@ +import { ApiResponse } from 'apisauce'; + +import api from '../../config/jiraAPI'; +export const addMessage = ( + content: Array<{ type: string; content: Array<{ text: string; type: string }> }>, + issueId: string +): Promise> => + api.post(`/issue/${issueId}/comment`, { + body: { + type: 'doc', + version: 1, + content, + }, + }); diff --git a/src/index.ts b/src/index.ts index 524cabb..0635604 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,11 +1,15 @@ import 'regenerator-runtime/runtime'; import express from 'express'; +import dotenv from 'dotenv'; + import UgoStatus from './controllers/slack/ugo_status'; import { initDirectivesJobs } from './utils/directives'; import GetPrs from './controllers/slack/pr_reminder'; import { createProbot, createNodeMiddleware } from 'probot'; import probotApp from './probotApp'; +dotenv.config(); + const port = parseInt(process.env.PORT || '8080', 10); const app = express(); diff --git a/src/probotApp/handlers/released.ts b/src/probotApp/handlers/released.ts new file mode 100644 index 0000000..50bf579 --- /dev/null +++ b/src/probotApp/handlers/released.ts @@ -0,0 +1,6 @@ +import { Context } from 'probot'; + +// eslint-disable-next-line @typescript-eslint/no-explicit-any +const released = async (context: Context): Promise => {}; + +export default released; diff --git a/src/probotApp/index.ts b/src/probotApp/index.ts index 8ec2895..0faf6ad 100644 --- a/src/probotApp/index.ts +++ b/src/probotApp/index.ts @@ -1,5 +1,6 @@ import { Probot } from 'probot'; import mergeable from './handlers/mergeable'; +import released from './handlers/released'; export = (app: Probot): void => { app.on( @@ -12,4 +13,6 @@ export = (app: Probot): void => { ], mergeable ); + + app.on(['pull_request.labeled'], released); }; diff --git a/yarn.lock b/yarn.lock index 7905846..e02677d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -970,6 +970,14 @@ anymatch@~3.1.1: normalize-path "^3.0.0" picomatch "^2.0.4" +apisauce@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/apisauce/-/apisauce-2.0.1.tgz#cf5af56ea6ff5145e6eeb8d4ba471c7e0662b8c4" + integrity sha512-mJBw3pKmtfVoP6oifnf7/iRJQtNkVb6GkYsVOXN2pidootj1mhGBtzYHOX9FVBzAz5QV2GMu8IJtiNIgZ44kHQ== + dependencies: + axios "^0.21.1" + ramda "^0.25.0" + apollo-link-http-common@^0.2.16: version "0.2.16" resolved "https://registry.yarnpkg.com/apollo-link-http-common/-/apollo-link-http-common-0.2.16.tgz#756749dafc732792c8ca0923f9a40564b7c59ecc" @@ -3854,6 +3862,11 @@ quick-format-unescaped@^4.0.1: resolved "https://registry.yarnpkg.com/quick-format-unescaped/-/quick-format-unescaped-4.0.1.tgz#437a5ea1a0b61deb7605f8ab6a8fd3858dbeb701" integrity sha512-RyYpQ6Q5/drsJyOhrWHYMWTedvjTIat+FTwv0K4yoUxzvekw2aRHMQJLlnvt8UantkZg2++bEzD9EdxXqkWf4A== +ramda@^0.25.0: + version "0.25.0" + resolved "https://registry.yarnpkg.com/ramda/-/ramda-0.25.0.tgz#8fdf68231cffa90bc2f9460390a0cb74a29b29a9" + integrity sha512-GXpfrYVPwx3K7RQ6aYT8KPS8XViSXUVJT1ONhoKPE9VAleW42YE+U+8VEyGWt41EnEQW7gwecYJriTI0pKoecQ== + range-parser@~1.2.1: version "1.2.1" resolved "https://registry.yarnpkg.com/range-parser/-/range-parser-1.2.1.tgz#3cf37023d199e1c24d1a55b84800c2f3e6468031" From 1718092f1d7751a3a81937fb75d8491c6f70b764 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Altrui?= Date: Thu, 18 Feb 2021 00:20:27 -0300 Subject: [PATCH 2/5] feat: added jira api and message service --- src/handlers/jira/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/handlers/jira/index.ts b/src/handlers/jira/index.ts index 09b4cc6..a5387d1 100644 --- a/src/handlers/jira/index.ts +++ b/src/handlers/jira/index.ts @@ -1,6 +1,7 @@ import { ApiResponse } from 'apisauce'; import api from '../../config/jiraAPI'; + export const addMessage = ( content: Array<{ type: string; content: Array<{ text: string; type: string }> }>, issueId: string From fd8dcb52f8b9f04a310a77c90b9e43442560198c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Altrui?= Date: Thu, 18 Feb 2021 00:25:51 -0300 Subject: [PATCH 3/5] feat: added version number retriever --- src/probotApp/utils.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/probotApp/utils.ts b/src/probotApp/utils.ts index f558f62..7d901e5 100644 --- a/src/probotApp/utils.ts +++ b/src/probotApp/utils.ts @@ -7,3 +7,9 @@ export const isWIPorHold = (labels: Array<{ name: string }>): boolean => console.log(label.name.toLowerCase()); return WIPandHoldNames.includes(label.name.toLowerCase()); }); + +export const getReleaseVersionFromComment = (comment: string): string | undefined => { + const regex = /([a-z]+@\d+.\d+.\d+)|(\d+.\d+.\d+)/gi; + + return comment.match(regex)?.[0]; +}; From 06a52442b05a68363c06db57e2aa391f23b6449b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Altrui?= Date: Thu, 18 Feb 2021 22:32:47 -0300 Subject: [PATCH 4/5] test From d53eba541198260cb8059d93b0ff733f47ac3803 Mon Sep 17 00:00:00 2001 From: Tomas Altrui Date: Tue, 30 Mar 2021 16:32:01 -0300 Subject: [PATCH 5/5] test --- src/probotApp/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/probotApp/index.ts b/src/probotApp/index.ts index 0faf6ad..e4756b6 100644 --- a/src/probotApp/index.ts +++ b/src/probotApp/index.ts @@ -6,10 +6,10 @@ export = (app: Probot): void => { app.on( [ 'pull_request.opened', - 'pull_request.edited', - 'pull_request.labeled', - 'pull_request.unlabeled', - 'pull_request.reopened', + 'pull_request.asd', + 'pull_request.asd', + 'pull_request.asd', + 'pull_request.asd', ], mergeable );