jira云端插件开发01-初步创建插件以及调用 Confluence API

安装镜像

参考链接按步骤安装即可:
DOCKER安装
WSL安装教程

安装@forge/api

npm install @forge/api

创建一个confluence插件

forge create
cd hello-world-app

发布与安装插件

forge deploy
forge install

使用docker运行插件

forge tunnel

额外信息

modules:
  macro:
    - key: hello-hello-world
      function: main
      title: hello
      description: Inserts Hello world!
  function:
    - key: main
      handler: index.run
app:
  //appId
  id: ari:cloud:ecosystem::app/722f6c9b-05ad-44e5-927d-b750b49f52d1
  //appName
  name: hello
  //需要的权限列表
permissions:
  scopes:
    - read:confluence-content.summary

至此就可以在编辑页面中查看刚刚创建好的app了
在这里插入图片描述

使用Confluence API

安装api模块:

npm install @forge/api @forge/ui

引入api及route模块:

import api, { route } from "@forge/api";

api的使用:

const fetchCommentsForContent = async (contentId) => {
  const res = await api
    .asUser()
    .requestConfluence(route`/rest/api/content/${contentId}/child/comment`);

  const data = await res.json();
  return data.results;
};

获取当前博文id:

import ForgeUI, { render, Fragment, Text, useProductContext } from "@forge/ui";
const context = useProductContext();

获取当前文章评论数:

const [comments] = useState(async () => await fetchCommentsForContent(context.contentId));

console.log(`Number of comments on this page: ${comments.length}`);

更新插件:(由于调用了api)

forge install --upgrade

tips:
由于涉及到用户权限,所以需要配置用户权限,使用官方的forge lint --fix并不会生效
需要手动在manifest.yml文件中改动以实现调用REST API

最终index.jsx文件

import api, { route } from "@forge/api";
import ForgeUI, { render, Fragment, Text, Macro, useProductContext, useState } from '@forge/ui';

const fetchCommentsForContent = async (contentId) => {
  const res = await api
    .asUser()
    .requestConfluence(route`/rest/api/content/${contentId}/child/comment`);

  const data = await res.json();
  return data.results;
};

const App = () => {
  const context = useProductContext();
  const [comments] = useState(async () => await fetchCommentsForContent(context.contentId));

  console.log(`Number of comments on this page: ${comments.length}`);

  return (
    <Fragment>
      <Text>Hello world!</Text>
      <Text>
        Number of comments on this page: {comments.length}
      </Text>
    </Fragment>
  );
};

export const run = render(
  <Macro
    app={<App />}
  />
);
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值