Tell me how can I make sure that notifications are written in mattermost?

I use youtrack standalone

8 comments
Comment actions Permalink
Official comment

Hello LeeTiK,

could you please elaborate a bit? If your question is related to integration between YouTrack and Mattermost, unfortunately, we don't have such integration.

However, the Mattermost service does provide a comprehensive API, which means it should be possible to create an integration based on YouTrack workflows, like the one described here: https://www.jetbrains.com/help/youtrack/standalone/slack-notifications-workflow.html.

Let us know if we can help you any further.

Comment actions Permalink

yes please help me

0
Comment actions Permalink

Ivan, we'd be happy to help. Would you mind elaborating on your question?

0
Comment actions Permalink

issue.comments.added.first() - возвращает вот такой текст при публикации сообщения вместе с картинкой, или без сообщения в комментарии, и как бы мне этот `![](image8.png)` убрать?

"text": "kjhkjhkhkjhkj![](image8.png)",
0
Comment actions Permalink
let text = firstAddedComment.text.replace('\[[^\[\]]*?\]\(.*?\)|^\[*?\]\(.*?\)',"");

Такая регулярка не работает

 

0
Comment actions Permalink

Он скобочки не понимает...

(image8.png)
0
Comment actions Permalink

скрипт отправки в mattermost уведомлений основанный на webhook

const SLACK_WEBHOOK_URL = 'https://mattermost.url/hooks/x4nbhjr9ejgd5c1cgfp6n7bhuc';

const entities = require('@jetbrains/youtrack-scripting-api/entities');
const http = require('@jetbrains/youtrack-scripting-api/http');

exports.rule = entities.Issue.onChange({
  title: 'Send notification to mattermost when an issue is reported, resolved, or reopened',
  guard: (ctx) => {
    return ctx.issue.becomesReported || ctx.issue.becomesResolved || ctx.issue.becomesUnresolved || !ctx.issue.comments.added.isEmpty();
  },
  action: (ctx) => {
    const issue = ctx.issue;

    const issueLink = '<' + issue.url + '|' + issue.id + '>';
    let message; let isNew;
    let text;

    if (issue.becomesReported) {
      message = '**Created**: ';
      isNew = true;
    } else if (issue.becomesResolved) {
      message = '**Resolved**: ';
      isNew = false;
    } else if (issue.becomesUnresolved) {
      message = '**Reopened**: ';
      isNew = false;
    } else if (issue.comments.isChanged){
      issue.comments.added.forEach(function(comment) {
        text = createGeneralMessage(issue);
        message = '';
        return;
      });
      isNew = false;
    }
    message += issue.summary;

    let changedByTitle = '';
    let changedByName = '';

    if (isNew) {
      changedByTitle = 'Created By';
      changedByName = issue.reporter.fullName;
    } else {
      changedByTitle = 'Updated By';
      changedByName = issue.updatedBy.fullName;
    }

    message += ' (' + issueLink + ')';
    
    if (text != null){
      message += '\n\n**Comments**:\n\n'+ text;
    }
    
    function createGeneralMessage(issue) {
  const firstAddedComment = issue.comments.added.first();
  let text = firstAddedComment.text.replace('!\[.*\]\(.*\)',"");
      console.log(text);
  const isMarkdown = firstAddedComment.isUsingMarkdown;
  issue.attachments.added.forEach(function (attachment) {
    if (isMarkdown) {
      text = text + '\n![' + attachment.name + '](' + attachment.fileUrl + ')';
    } else {
      text = text + '\n[file:' + attachment.name + ']';
    }
  });
  return text;
}
    
    const payload = {
      'text': message,
      'username': changedByName,
      "props": {
        "card": "**State**: "+issue.fields.State.name + "\n\n**Priority**: "+issue.fields.Priority.name+"\n\n---\n\n"+issue.description
          }
    };

    const connection = new http.Connection(SLACK_WEBHOOK_URL, null, 2000);
    connection.addHeader("Content-Type", "application/json");
    const response = connection.postSync('', [], JSON.stringify(payload));
    if (!response.isSuccess) {
      console.warn('Failed to post notification to Slack. Details: ' + response.toString());
    }
  },
  requirements: {
    Priority: {
      type: entities.EnumField.fieldType
    },
    State: {
      type: entities.State.fieldType
    },
    Assignee: {
      type: entities.User.fieldType
    }
  }
});
0
Comment actions Permalink

Здравствуйте,

Прошу прощения за задержку с ответом. Ваше регулярное выражение не захватывает восклицательный знак в начале. Вот такое регулярное выражение должно сработать: `!\[[\]]?\]\(.*?\)|^\[*?\]\(.*?\)`.

На всякий случай, вот на этом сайте можно проверить корректность регулярного выражения: https://regex101.com/.

Надеюсь, это поможет.

0

Please sign in to leave a comment.