Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ npm link
# Bearer authentication (recommended)
export JIRA_HOST=your-jira-instance.atlassian.net
export JIRA_API_TOKEN=your-api-token
export JIRA_API_VERSION=auto # optional: auto (default), 2, 3

# Basic authentication (optional)
export JIRA_HOST=your-jira-instance.atlassian.net
export JIRA_API_TOKEN=your-api-token
export JIRA_USERNAME=your-email@company.com
export JIRA_API_VERSION=auto # optional: auto (default), 2, 3
```

4. **Verify connection:**
Expand Down Expand Up @@ -101,11 +103,20 @@ jira config --server https://yourcompany.atlassian.net \
jira config set server https://yourcompany.atlassian.net
jira config set token your-api-token
jira config set username your-email@company.com # optional
jira config set apiVersion auto # optional: auto (default), 2, 3

# Show current configuration
jira config --show
```

### Jira REST API Version

By default, the CLI uses `auto` mode: it tries Jira REST API v3 first and automatically retries with v2 if needed. If a fallback happens, the CLI keeps using the working version for the rest of the process.

You can override the behavior:
- Config: `jira config set apiVersion auto|2|3`
- Env: `JIRA_API_VERSION=auto|2|3`

### Option 2: Environment Variables

You can configure the CLI using environment variables in either a new or legacy format:
Expand All @@ -115,18 +126,21 @@ You can configure the CLI using environment variables in either a new or legacy
# Bearer authentication
export JIRA_HOST="your-jira-instance.atlassian.net"
export JIRA_API_TOKEN="your-api-token"
export JIRA_API_VERSION="auto" # optional: auto (default), 2, 3

# Basic authentication (add username)
export JIRA_HOST="your-jira-instance.atlassian.net"
export JIRA_API_TOKEN="your-api-token"
export JIRA_USERNAME="your-email@company.com"
export JIRA_API_VERSION="auto" # optional: auto (default), 2, 3
```

#### Legacy format (JIRA_DOMAIN)
```bash
export JIRA_DOMAIN="your-domain.atlassian.net"
export JIRA_USERNAME="your-email@company.com"
export JIRA_API_TOKEN="your-api-token"
export JIRA_API_VERSION="auto" # optional: auto (default), 2, 3
```

### Getting Your API Token
Expand Down
4 changes: 3 additions & 1 deletion docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ const client = new JiraClient(config)
```

**Parameters:**
- `config` (Object): Configuration object containing server, username, and token
- `config` (Object): Configuration object containing server, username, token, and optional apiVersion (`auto`, `2`, `3`)

When `apiVersion` is `auto`, the client starts with v3 and retries with v2 on certain endpoint failures; the successful version is kept for the rest of the process.

#### Methods

Expand Down
19 changes: 15 additions & 4 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ class Config {
},
token: {
type: 'string'
},
apiVersion: {
type: 'string',
enum: ['auto', '2', '3'],
default: 'auto'
}
}
});
Expand Down Expand Up @@ -62,7 +67,8 @@ class Config {
process.env.JIRA_HOST :
`https://${process.env.JIRA_HOST}`,
username: process.env.JIRA_USERNAME || '', // Empty username for token-only auth
token: process.env.JIRA_API_TOKEN
token: process.env.JIRA_API_TOKEN,
apiVersion: process.env.JIRA_API_VERSION || this.get('apiVersion') || 'auto'
};
}

Expand All @@ -73,7 +79,8 @@ class Config {
process.env.JIRA_DOMAIN :
`https://${process.env.JIRA_DOMAIN}`,
username: process.env.JIRA_USERNAME,
token: process.env.JIRA_API_TOKEN
token: process.env.JIRA_API_TOKEN,
apiVersion: process.env.JIRA_API_VERSION || this.get('apiVersion') || 'auto'
};
}

Expand All @@ -93,7 +100,8 @@ class Config {
return {
server: this.get('server'),
username: this.get('username') || '',
token: this.get('token')
token: this.get('token'),
apiVersion: process.env.JIRA_API_VERSION || this.get('apiVersion') || 'auto'
};
}

Expand Down Expand Up @@ -137,10 +145,12 @@ class Config {
console.log('Server:', chalk.green(process.env.JIRA_HOST));
console.log('Username:', chalk.green(process.env.JIRA_USERNAME || '(token auth)'));
console.log('Token:', chalk.green('***configured***'));
console.log('API Version:', chalk.green(process.env.JIRA_API_VERSION || 'auto'));
} else if (process.env.JIRA_DOMAIN) {
console.log('Server:', chalk.green(process.env.JIRA_DOMAIN));
console.log('Username:', chalk.green(process.env.JIRA_USERNAME));
console.log('Token:', chalk.green('***configured***'));
console.log('API Version:', chalk.green(process.env.JIRA_API_VERSION || 'auto'));
}
}

Expand All @@ -149,6 +159,7 @@ class Config {
console.log('Server:', chalk.green(config.server || 'Not set'));
console.log('Username:', chalk.green(config.username || '(Bearer auth)'));
console.log('Token:', config.token ? chalk.green('Set (hidden)') : chalk.red('Not set'));
console.log('API Version:', chalk.green(config.apiVersion || 'auto'));
}

if (this.isConfigured()) {
Expand All @@ -160,4 +171,4 @@ class Config {

}

module.exports = Config;
module.exports = Config;
Loading