# 支持事件

目前 Learning Lab 支持的事件包括：

- push
- tag_push
- note
- confidential_note
- issue
- confidential_issue
- merge_request
- pipeline
- Pages
- wiki
- commit
- deployment
- alert


## push

使用push类型来监听用户仓库的推送代码事件

### 示例

在使用`transitions`中监听用户的push事件并执行相应的`action`，当用户向`feature1`推送代码的时候，触发相应的action

```yaml
step1:
  link: '{{first_issue_url}}'
  description: "第一步"
  transitions:
    events: ['push']
    with: 'feature1'
    action:
      - type: issue_comment.created
        with: comment.md
    to: step9
```

### Options

当`events`为push的时候，支持的参数

| 参数 | 类型 | 描述 | 默认 | 是否为必要参数 |
| --- | --- | --- | --- | --- | 
| with | String | 监听用户推送到的分支 |  | ✓ |


## note

使用push类型来监听用户仓库的推送代码事件

### 示例

在使用`transitions`中监听用户的note(评论)事件并执行相应的`action`，当用户回复相应内容的时候，触发相应的`action`

```yaml
step1: 
  link: '{{first_issue_url}}'
  description: "不同操作系统的安装介绍"
  transitions:
    - events: ['note_events']
      with: A
      action: 
        - type: issue_comment.created
          with: 004_3_window_git_install.md
        - type: choice
          with: next.md
      to: step2
    - events: ['note_events']
      with: B
      action: 
        - type: issue_comment.created
          with: 004_4_macOS_git_install.md
        - type: choice
          with: next.md
      to: step2
    - events: ['note_events']
      with: C
      action: 
        - type: issue_comment.created
          with: 004_5_linux_git_install.md
        - type: choice
          with: next.md
      to: step2
```

也可以使用正则匹配来匹配用户输入评论的内容，如果用户评论的内容和正则表达式相匹配，则出发相应的`action`

```yaml
step1:
  link: '{{first_issue_url}}'
  description: "使用正则匹配标题"
  transitions:
    - events: ['note_events']
      left: '/^#{1,6}\s.+/'
      operator: regexp
      right: '{{object_attributes.note}}'
      action:
        - type: issue_comment.created
          with: nice_job.md
      to: step2
```

### Options

当`events`为note的时候，支持的参数

| 参数 | 类型 | 描述 | 默认 | 是否为必要参数 |
| --- | --- | --- | --- | --- | 
| with | String | 用户回复的内容 |  |   |
| left | String | 正则表达式 |  |   |
| operator | String | 操作符，这里使用正则匹配，应该为regexp |  |   |
| right | String | 监听到符合条件的对象的属性，object_attributes为对象的所有属性，这里用到的属性为note |  |   |


## issue

使用push类型来监听用户仓库的推送代码事件

### 示例

在使用`transitions`中监听用户的issue事件并执行相应的`action`，下面的示例是指当用户关闭一个issue的时候，触发相应的action

```yaml
step6:
  link: '{{chapter_3_issue}}'
  description: "完成当前章节学习"
  transitions:
    events: ['close_issue']
    action:
      - type: create_issue
        title: "Markdown ：链接"
        with: 004_1_link_basic.md
        store:
          chapter_4_issue: '{{result.data.html_url}}'
      - type: issue_comment.created
        with: 003_5_end_2.md
    to: end
```

### Options

`close_issue` 事件无需额外的参数，系统默认会匹配step中的`link`参数指向的issue