# ticket-manager-workspace-plugin

Forge UI Kit app that renders a Jira issue context card titled `Ticket Workspace`.

The card resolves the Jira issue's Case Workspace, shows its status, Brief Summary, and Primary Lark Group, and provides the supported Workspace and Group creation actions. The resolver defaults to a mock backend for local development. Remote mode uses Forge backend `fetch` from `@forge/api` to call the ticket-manager APIs.

The issue context is visible only in these Jira projects: `ST`, `TCID`, `TCAB`, `APID`, `EMID`, `TCB`, `JPID`, `NAID`, `TCOC`, `GTOC`, and `TCT`.

## Local Setup

```bash
make -C ../../../packages/sdk-ts generate-ticket-manager
npm install
npm run lint
npm test
forge lint
```

## Forge Runtime Variables

Mock mode is the default and does not require backend variables.

```bash
forge variables set BACKEND_MODE mock
```

Remote mode calls ticket-manager through Forge backend `fetch`:

```bash
forge variables set BACKEND_MODE remote
forge variables set BACKEND_BASE_URL https://dev.devops.pingcap.com
forge variables set FRONTEND_BASE_URL https://dev.devops.pingcap.com
forge variables set --encrypt BACKEND_API_KEY YOUR_API_KEY
```

Forge variables are environment-specific. Set production values explicitly when deploying production, for example:

```bash
forge variables set BACKEND_MODE remote -e production
forge variables set BACKEND_BASE_URL https://prod.devops.pingcap.com -e production
forge variables set FRONTEND_BASE_URL https://ticket-manager.ops.pingcap.net -e production
forge variables set --encrypt BACKEND_API_KEY YOUR_API_KEY -e production
```

When `BACKEND_MODE=remote`, all three URL/API Key variables are required. The resolver sends the encrypted `BACKEND_API_KEY` as `X-API-KEY`. The Secret is only read by the Forge function and is never returned to the UI or written to logs.

The resolver uses Issue Binding and Workspace APIs to select the newest firing Case Workspace for the current Jira issue. If no Case Workspace exists, it calls `SyncCaseWorkspaceOfIssue` and then creates a Primary Lark Group. Brief Summary comes from the curated timeline API. Primary Group details come from the Workspace's `primary_chat_group_cr_id`, and its metadata join link is used for the UI Join action.

## Backend Egress

Forge requires static egress domains in `manifest.yml`. The app allows backend fetches to:

* `https://dev.devops.pingcap.com`
* `https://staging.devops.pingcap.com`
* `https://prod.devops.pingcap.com`

After adding scopes or egress permissions, redeploy and upgrade the Jira installation.

## Deployment

### For test

```bash
forge deploy --non-interactive -e development
```

Install into a Jira test site when the site URL is available:

* For first install.

```bash
forge install --non-interactive --site <your-personal-site>.atlassian.net --product jira --environment development
```


* For update:

```bash
forge install --upgrade --non-interactive --site <your-personal-site>.atlassian.net --product jira --environment development
```

Use `--upgrade` instead of a fresh install after changing scopes or permissions.


### For prod

```bash
forge deploy --non-interactive -e production

forge install --upgrade --non-interactive --site tidb.atlassian.net --product jira --environment production
```
