Skip to content

Commit

Permalink
Update getting-started-with-gitproject-health.md
Browse files Browse the repository at this point in the history
add an script example for the model connector between Jira and git
  • Loading branch information
alkalinan authored Oct 17, 2024
1 parent 10bb670 commit 825414c
Showing 1 changed file with 79 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
layout: page
author: Benoit Verhaeghe
author: Benoit Verhaeghe & Nicolas Hlad
background: '/img/bg-wiki.jpg'
title: 'Getting started with GitProject Health'
toc: true
Expand Down Expand Up @@ -208,6 +208,84 @@ GPJCConnector new
connect
```


### Jira connector in action: retrieving the ticket type associated with merge requests

In this complete example, we retrieve the merge request (MR) inside a group of project and connect them to their associated Jira Ticket.
To connect a issue with an MR, we look for MR that mention the issue key id in their title. For instance.
`[WERH-918] feat: Add specific month to salary` match the issue `(WERH-918) month integration`.

```st
"set up the git model"
model := GLPHEModel new name: 'myModel'.
"set up the API, here for gitlab"
glphApi := GLPHApi new
privateToken: '<YOUR-TOKEN>';
baseAPIUrl:'<YOUR-GITLAB-URL>';
yourself.
"set up the gitlab importer"
glhImporter := GLPHModelImporter new
repoApi: glphApi;
glhModel: model;
makeGlobal: 'myImporter';
withFiles: false;
withCommitDiffs: false.
"setup the JiraAPI"
jpAPI := JiraPharoAPI new endpoint: '<myCompany>.atlassian.net';
basePath: 'rest/api/latest';
beHttps;
user: '<USER-EMAIL-ACCOUNT>';
apiToken: '<YOUR-JIRA-API-TOKEN>'.
"setup the Jira Importer"
jpImporter := JiraPharoImporter new
model: model;
api: jpAPI;
yourself.
"importing a group of projects"
grp := glhImporter importGroup: 1234.
"for each project"
grp allProjectstoScope do: [ :project |
"import the merge request"
glhImporter importMergeRequests: project
since: (Date today - 30 day) asDateAndTime
until: (Date today).
"import the latest commits"
(glhImporter importAndLoadLatestsCommitsOfProject: project ).
].
"collect all issues related to these projects"
issues := (((grp toScope: GLHCommit)
collect: [ :commit | commit commitCreator])
reject: [:user | user id isNil]) asSet
flatCollect: [ :user |
|email mergeRequests |
"import the jira issue from each user account"
email := user username , '@my-email-domain.com'.
jpImporter importAllCurrentAndPastIssuesOf: email.
].
"achieve the connection between the Git and the Jira model"
"the connection is made for all MR that includes in their title the key of an issue. same for commit"
GPJCConnector new
gpModel: glhImporter glhModel;
jiraModel: jpImporter model;
connect.
"collect the merge request found previously"
mergeRequests := (grp toScope: GLPHEMergeRequest). "70 founds"
"select the MR with a matching jira issue"
mrWithTicket := ( mergeRequests asOrderedCollection select: [ :mr |
mr jiraIssue isNotNil.
]). "66 of them associated with a Jira ticket"
"get the issue type and output their occurring rate"
(mrWithTicket collect: [ :mr | mr jiraIssue type name ]) asBag
```

### Famix Connector

> You will probably have to learn what Famix is.
Expand Down

0 comments on commit 825414c

Please sign in to comment.