Organize the workflow in such a way that when you commit to git, comments were automatically added to the TrackStudio task with different types of messages and the text of this comment was the text of the commit message.
Here is an example for gmail.com:mail.pop3.apop.enable=\ mail.store.forward= email mail.store.fwdaddress=email mail.store.host=pop mail.store.password= mail.store.port= mail.store.protocol= mail.store.user= , email, trackstudio.emailSubmission=yes trackstudio.mailimport.interval=
More details are described in the documentation .mail.pop3.apop.enable=\ mail.store.forward=yes mail.store.fwdaddress=mymail@gmail.com mail.store.host=pop.gmail.com mail.store.password=password mail.store.port=995 mail.store.protocol=pop3s mail.store.user=srvmail@gmail.com
- / **
- * The script creates an import rule for the ancestor task when creating a child task.
- * /
- import com.trackstudio.app.adapter.AdapterManager;
- import com.trackstudio.exception.GranException;
- import com.trackstudio.secured. *;
- import com.trackstudio.securedkernel.SecuredMailImportAdapterManager;
- import com.trackstudio.securedkernel.SecuredStepAdapterManager;
- import java.util. *;
- import com.trackstudio.secured.SecuredUserBean;
- import com.trackstudio.app.session. *;
- import com.trackstudio.app.csv.CSVImport;
- try {
- // object for working with mail import rules
- SecuredMailImportAdapterManager mam = AdapterManager.getInstance ()
- .getSecuredMailImportAdapterManager ();
- // contains methods for working with message types
- SecuredStepAdapterManager sam = AdapterManager.getInstance ()
- .getSecuredStepAdapterManager ();
- // list of available message types for task and current user
- ArrayList arrMS = sam.getAvailableMstatusList (task.getSecure (), task.getId ());
- // type of message
- SecuredMstatusBean curMS = null ;
- String pefixStr = "new" ;
- / **
- * Check the type of category of the created task.
- * If the task category is “Error” = category name in TS
- * /
- if (task.getCategory (). getName (). equals ( "Error" ))
- pefixStr = "bug" ;
- / **
- * Generate a key for importing messages from the current task:
- * prefix + parent task number + # + task number
- * this key should be in the subject line
- * eg:
- * new759 # 2845 any text, anyway it will be ignored when adding a message.
- * /
- String mailimKey = pefixStr + task.getParent (). GetNumber () + "#" + task.getNumber ();
- / **
- * Do I need to create a rule.
- * Since an ancestor task can have several subtasks,
- * it is necessary to check the existence of the import rule,
- * so as not to produce them.
- * /
- boolean found = false ;
- for ( int i = 0; i <arrMS.size (); i ++) {
- curMS = (SecuredMstatusBean) arrMS.get (i);
- msn = curMS.getName ();
- // "Commentary" or "Comment" is the name of the message type
- if (msn.compareToIgnoreCase ( "Comment" ) == 0 || msn.compareToIgnoreCase ( "Comment" ) == 0) {
- // Get data by root user
- SecuredUserBean adminUser = new SecuredUserBean (CSVImport.findUserIdByLogin ( "root" ), sc);
- // Current user context
- SessionContext needSc = task.getSecure ();
- // check whether root has logged in
- if (SessionManager.getInstance (). existUserSession (adminUser.getUser ())) {
- for (SessionContext curSc: SessionManager.getInstance (). getSessions ()) {
- if (curSc.getUser (). getLogin (). equals ( "root" )) {
- // if yes then we get its context
- needSc = curSc;
- break ;
- }
- }
- }
- else {
- // if not, create its context
- needSc = SessionManager.getInstance (). getSessionContext (
- SessionManager.getInstance (). Create (adminUser.getUser ()));
- }
- if (! found)
- for (SecuredMailImportBean curMailS: mam.getAllAvailableMailImportList (needSc, task.getParentId ())) {
- // We are looking for the rule of importing new tasks from the ancestor.
- found = curMailS.getKeywords (). equals (pefixStr + task.getParent (). getNumber ());
- if (found)
- break ;
- }
- if (! found) {
- / **
- * if not found, then create a new import rule for the ancestor
- * as root, as TS supports the ability to create
- * users of individual rules for importing mail, you must
- * so that this rule could be seen by everyone.
- * /
- mam.createMailImport (needSc, pefixStr + task.getParent (). getNumber (),
- task.getParentId (), pefixStr + task.getParent (). getNumber (), 1, i,
- task.getCategoryId (), curMS.getId (), "" , true , false );
- found = true ;
- }
- }
- }
- // Add a value for the UDF field with the name "Branch name in git".
- AdapterManager.getInstance (). GetSecuredUDFAdapterManager (). SetTaskUDFValueSimple (
- task.getSecure (), task.getId (), “Branch Name in git” , mailimKey);
- }
- catch (GranException e) {
- throw new com.trackstudio.exception.UserMessageException (e.getMessage ());
- }
- return task;
The script has been created, now in TS we select in the menu “Task management -> Processes”, first click on the process with the name “Change”, then select the operation types tab and click on the operation with the name “Comment”
- / **
- * The script changes the type of the message being imported if it finds it in the message body.
- * construct [new_state = type], where type can be done or start
- * /
- import java.util. *;
- import java.util.regex. *;
- import java.io. *;
- try {
- if (message.description! = null )
- {
- String [] tempArr = null ;
- // Looking for the construction we need in the message
- String pattern = ". * \\ [(\\ w *) = (\\ w *) \\]. *" ;
- Pattern p = Pattern.compile (pattern, Pattern.MULTILINE);
- Matcher m = p.matcher (message.description);
- if (m.find ())
- tempArr = new String [] {m.group (1), m.group (2)};
- // whether the first parameter is scanned by the directive to change the type of message
- if (tempArr! = null && tempArr [0] .toLowerCase (). equals ( "new_state" )) {
- // determine what type to change the current message type
- if (tempArr [1] .toLowerCase (). equals ( "done" )) {
- // Remove the directive from the message
- message.description = message.description.replaceFirst ( "\\ [new_state = done \\]" , "" );
- // check which task belongs to
- if (message.getTask (). getCategory (). getName (). equals ( "Change" ))
- // set the new message type by its name
- message.setMstatus ( “Finish” );
- if (message.getTask (). getCategory (). getName (). equals ( "Error" ))
- message.setMstatus ( “Fix” );
- }
- if (tempArr [1] .toLowerCase (). equals ( "start" )) {
- message.description = message.description.replaceFirst ( "\\ [new_state = start \\]" , "" );
- if (message.getTask (). getCategory (). getName (). equals ( "Change" ) ||
- message.getTask (). getCategory (). getName (). equals ( “Error” ))
- message.setMstatus ( “Get started” );
- }
- }
- }
- }
- catch (Exception e) {
- throw new com.trackstudio.exception.UserMessageException (e.printStackTrace ());
- }
- return message;
socket = l:TCP_NODELAY=1 socket = r:TCP_NODELAY=1 debug = 7 output = stunnel.log client = yes [ssmtp] accept = 127.0.0.1:465 connect = smtp.gmail.com:465
And in order for stunnel to start as a service, we automatically execute on the command line:"C: \ Program Files \ stunnel \ stunnel.exe" –installsource: Sending letters from the Windows command line using a GMail account
#! / bin / sh
case "$ 2, $ 3" in
merge ,)
perl - i.bak - ne 's / ^ / # /, s / ^ # # / # / if / ^ Conflicts / ... / # /; print ' "$ 1" ;;
*) ;;
esac
if [ "` git branch | grep -e "^ \ *. \ (new \ | bug \) [0-9] \ + # [0-9] \ +" | cut -f2 -d '' `"! = "" ]; then
# Put the keys to send the letter to the beginning of the file with the message.
echo sendmail > temp_msg
echo "to = srvemail@gmail.com" >> temp_msg
echo "[new_state = done]" >> temp_msg
cat $ 1 >> temp_msg
cat temp_msg > $ 1
rm temp_msg
fi
#! / bin / sh
# we get from the variable GIT_AUTHOR_IDENT email of the current committer
sender = `git var GIT_COMMITTER_IDENT | cut -f1 -d '>' | cut -f 2 -d '<' `
# check the presence of the sendmail text in the first line of the message
if [ `git log -1 | sed "s / [] * // g" | grep -e "^ sendmail $" ` == " sendmail " ]; then
# form the subject of the message, which is taken from the name of the branch
# but this is a wish, you can make the topic be taken from the first line of the main text of the message
subject = `git branch | grep -e "^ \ *. \ (new \ | bug \) [0-9] \ + # [0-9] \ +" | cut -f2 -d '' `
if [ "` git log -1 | sed " s / [ ] * // g " | gre grep -e " ^ newroot \ = " | cut -f2 -d '= "` " ! = " " ]; then
subject = `git log -1 | sed "s / [] * // g" | grep -e "^ newroot \ =" | cut -f2 -d '=' | cut -f1 -d '#' `
subject = "$ subject #` git branch | grep -e "^ \ *. \ (new \ | bug \) [0-9] \ + # [0-9] \ +" | cut -f2 -d '# '`"
fi
# determined from the third line of the message of the commit mail,
# to which you need to send a letter
# by default put the current commitr's email.
to = $ sender
if [ "` git log -1 | sed "s / [] * // g" | grep -e "^ [Tt] [Oo] \ =" | cut -f2 -d '= "` " ! = " " ]; then
to = `git log -1 | sed "s / [] * // g" | grep -e "^ [Tt] [Oo] \ =" | cut -f2 -d '=' "`
fi
# create patch file name
patchname = "$ (date +% j% H% M% s) .patch"
# save the diff commitcomit,
( git diff-index -p -M HEAD ^) > $ patchname
# take the last message from the git log with the exception of the control text
git log - 1 | grep - v "^ Date:" | grep - v "^ commit" | grep - v "^ Author:" | grep - v "* Signed-off-by:" | grep - v "^ [] * sendmail [] * $" | grep - v "^ [] * newroot \ =" | grep - v "^ [] * [Tt] [Oo] \ =" | grep - v ". * $ subject. *" | sed -e "/ ^ [] * $ / d" -e "/ ^ $ / d" >> temp.tmp
echo "shortstat" >> temp.tmp
git diff-index - stat HEAD ^ >> temp.tmp
# send by means of blat
blat - charset "utf-8" -f $ sender - server localhost - port 465 - u useremail@gmail.com - pw password - to $ body - temp.tmp - subject $ subject - base64 - attach $ patchname > logSendMail. log
rm $ patchname
rm temp.tmp
edit logSendMail.log
sleep 2 s
rm logSendMail.log
fi
newroot=new458
Important: each parameter must be on a separate line, the number of spaces or tabs do not affect its detection.$ git add --all & git gui
$ git checkout -b _
Source: https://habr.com/ru/post/113554/
All Articles