关于 atlassianapi
面向使用 Jira 和 Confluence 的开发者及 Agent 工作流的 Atlassian API 技能。涵盖 REST API 操作、webhook,以及同步拉取请求、发布发行说明等自动化示例。
主要功能
- 01Jira 问题与冲刺操作
- 02Confluence 页面管理与搜索
- 03Webhook 注册与处理
- 04Jira 和 Confluence 自动化示例
适用场景
- 01搜索和更新 Jira 问题
- 02将发行说明发布到 Confluence
- 03将拉取请求与 Jira 同步
- 04处理 Jira 问题 webhook
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ thelobbi/ claude --skill atlassianapi安装后在 Claude Code 中输入/atlassianapi确认已加载。
详细介绍
Atlassian API 技能
为 Golden Armada AI Agent Fleet Platform 提供全面的 Atlassian API 集成能力。
何时使用此技能
在以下场景中使用此技能:
- Jira REST API 集成
- Confluence REST API 集成
- Atlassian Webhook
- 自动化和脚本编写
- 跨平台同步
身份验证
API Token(Cloud)
import requests
from requests.auth import HTTPBasicAuth
auth = HTTPBasicAuth('[email protected]', 'API_TOKEN')
headers = {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
base_url = 'https://your-domain.atlassian.net'
Python 客户端库
from atlassian import Jira, Confluence
jira = Jira(
url='https://your-domain.atlassian.net',
username='[email protected]',
password='API_TOKEN',
cloud=True
)
confluence = Confluence(
url='https://your-domain.atlassian.net',
username='[email protected]',
password='API_TOKEN',
cloud=True
)
Jira REST API
问题
# 创建问题
response = requests.post(
f'{base_url}/rest/api/3/issue',
auth=auth,
headers=headers,
json={
'fields': {
'project': {'key': 'GA'},
'summary': 'Implement agent monitoring',
'description': {
'type': 'doc',
'version': 1,
'content': [
{
'type': 'paragraph',
'content': [
{'type': 'text', 'text': 'Description text'}
]
}
]
},
'issuetype': {'name': 'Story'},
'priority': {'name': 'High'},
'labels': ['backend', 'monitoring']
}
}
)
# 获取问题
response = requests.get(
f'{base_url}/rest/api/3/issue/GA-123',
auth=auth,
headers=headers
)
issue = response.json()
# 更新问题
response = requests.put(
f'{base_url}/rest/api/3/issue/GA-123',
auth=auth,
headers=headers,
json={
'fields': {
'summary': 'Updated summary'
}
}
)
# 转换问题状态
# 首先,获取可用的状态转换
transitions = requests.get(
f'{base_url}/rest/api/3/issue/GA-123/transitions',
auth=auth,
headers=headers
).json()
# 然后执行状态转换
requests.post(
f'{base_url}/rest/api/3/issue/GA-123/transitions',
auth=auth,
headers=headers,
json={'transition': {'id': '31'}} # 来自可用状态转换的 ID
)
# 添加评论
requests.post(
f'{base_url}/rest/api/3/issue/GA-123/comment',
auth=auth,
headers=headers,
json={
'body': {
'type': 'doc',
'version': 1,
'content': [
{
'type': 'paragraph',
'content': [
{'type': 'text', 'text': 'Comment text'}
]
}
]
}
}
)
JQL 搜索
# 搜索问题
jql = 'project = GA AND status = "In Progress" ORDER BY created DESC'
response = requests.get(
f'{base_url}/rest/api/3/search',
auth=auth,
headers=headers,
params={
'jql': jql,
'maxResults': 50,
'fields': 'summary,status,assignee,priority'
}
)
results = response.json()
for issue in results['issues']:
print(f"{issue['key']}: {issue['fields']['summary']}")
冲刺和看板
# 获取看板
boards = requests.get(
f'{base_url}/rest/agile/1.0/board',
auth=auth,
headers=headers
).json()
# 获取看板的冲刺
board_id = 1
sprints = requests.get(
f'{base_url}/rest/agile/1.0/board/{board_id}/sprint',
auth=auth,
headers=headers
).json()
# 获取冲刺中的问题
sprint_id = 10
issues = requests.get(
f'{base_url}/rest/agile/1.0/sprint/{sprint_id}/issue',
auth=auth,
headers=headers
).json()
# 将问题移至冲刺
requests.post(
f'{base_url}/rest/agile/1.0/sprint/{sprint_id}/issue',
auth=auth,
headers=headers,
json={'issues': ['GA-123', 'GA-124']}
)
\`\`\`
## Confluence REST API
### 页面
\`\`\`python
# 创建页面
response = requests.post(
f'{base_url}/wiki/rest/api/content',
auth=auth,
headers=headers,
json={
'type': 'page',
'title': 'Agent Architecture',
'space': {'key': 'GA'},
'body': {
'storage': {
'value': '<h1>Overview</h1><p>Content here...</p>',
'representation': 'storage'
}
}
}
)
# 获取页面
page = requests.get(
f'{base_url}/wiki/rest/api/content/12345',
auth=auth,
headers=headers,
params={'expand': 'body.storage,version'}
).json()
# 更新页面
requests.put(
f'{base_url}/wiki/rest/api/content/12345',
auth=auth,
headers=headers,
json={
'type': 'page',
'title': 'Updated Title',
'body': {
'storage': {
'value': '<h1>Updated Content</h1>',
'representation': 'storage'
}
},
'version': {'number': page['version']['number'] + 1}
}
)
# 搜索页面
results = requests.get(
f'{base_url}/wiki/rest/api/content/search',
auth=auth,
headers=headers,
params={'cql': 'space = GA AND text ~ "agent"'}
).json()
\`\`\`
## Webhooks
### Jira Webhook 处理程序
\`\`\`python
from flask import Flask, request
app = Flask(__name__)
@app.route('/webhooks/jira', methods=['POST'])
def handle_jira_webhook():
event = request.json
event_type = event.get('webhookEvent')
if event_type == 'jira:issue_created':
issue = event['issue']
handle_issue_created(issue)
elif event_type == 'jira:issue_updated':
issue = event['issue']
changelog = event.get('changelog', {})
handle_issue_updated(issue, changelog)
elif event_type == 'sprint_started':
sprint = event['sprint']
handle_sprint_started(sprint)
return {'status': 'ok'}
def handle_issue_created(issue):
print(f"Issue created: {issue['key']}")
def handle_issue_updated(issue, changelog):
for item in changelog.get('items', []):
if item['field'] == 'status':
print(f"Issue {issue['key']} status changed: {item['fromString']} -> {item['toString']}")
\`\`\`
### 注册 Webhook
\`\`\`python
# 注册 Jira webhook
webhook = requests.post(
f'{base_url}/rest/webhooks/1.0/webhook',
auth=auth,
headers=headers,
json={
'name': 'Golden Armada Integration',
'url': 'https://your-app.com/webhooks/jira',
'events': [
'jira:issue_created',
'jira:issue_updated',
'sprint_started',
'sprint_closed'
],
'filters': {
'issue-related-events-section': 'project = GA'
}
}
)
\`\`\`
## 自动化方案
### 将 GitHub PR 同步到 Jira
\`\`\`python
async def sync_pr_to_jira(pr_data: dict):
# 从分支名称中提取 Jira 问题键(例如,feature/GA-123-add-feature)
branch = pr_data['head']['ref']
match = re.search(r'(GA-\d+)', branch)
if not match:
return
issue_key = match.group(1)
# 添加包含 PR 链接的评论
jira.add_comment(
issue_key,
f"PR opened: [{pr_data['title']}]({pr_data['html_url']})"
)
# 如果 PR 已准备就绪,则将问题转换为“In Review”
if not pr_data.get('draft'):
jira.transition_issue(issue_key, 'In Review')
\`\`\`
### Auto-create Release Notes
\`\`\`python
def generate_release_notes(version: str, project_key: str = 'GA'):
# Get all issues in the release
jql = f'project = {project_key} AND fixVersion = "{version}" ORDER BY issuetype'
issues = jira.jql(jql)['issues']
# Group by type
features = [i for i in issues if i['fields']['issuetype']['name'] == 'Story']
bugs = [i for i in issues if i['fields']['issuetype']['name'] == 'Bug']
# Generate markdown
notes = f"# Release {version}\n\n"
notes += "## Features\n"
for issue in features:
notes += f"- [{issue['key']}] {issue['fields']['summary']}\n"
notes += "\n## Bug Fixes\n"
for issue in bugs:
notes += f"- [{issue['key']}] {issue['fields']['summary']}\n"
# Create Confluence page
confluence.create_page(
space='GA',
title=f'Release Notes - {version}',
body=markdown_to_confluence(notes),
parent_id=RELEASE_NOTES_PARENT_ID
)
\`\`\`
## Golden Armada Commands
\`\`\`bash
# Sync with Atlassian
/atlassian-sync --jira --confluence
# Create Jira issue from template
/jira-create --type story --template agent-feature
# Update Confluence docs from code
/confluence-publish --from docs/ --space GA
\`\`\`
评论
支持 Markdown