first commit
This commit is contained in:
commit
64bd9a46d2
|
|
@ -0,0 +1,73 @@
|
|||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
|
||||
|
||||
Copyright 2024 jlzhao19
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
# Issue_Linker_Bot
|
||||
|
||||
## 介绍
|
||||
|
||||
欢迎了解 Issue Linker Bot,这是一款智能、高效的项目管理协同工具,专为软件开发团队设计,旨在提升任务管理的效率,自动化地处理项目中的 Issue 相关性分析与跟踪。这款 Bot 充分利用自然语言处理技术,通过对 Issue 数据的智能解析,帮助开发人员更加高效地掌握和管理工作流。
|
||||
核心功能
|
||||
|
||||
- 自动识别 Issue 关系: Issue Linker Bot 可以智能地分析新创建的 Issue,并与历史 Issue 进行比对,自动识别它们之间的关联。无论是任务相关、子任务关系、阻碍还是重复问题,该 Bot 都能自动检测并推荐,帮助您及时掌握项目的整体关联。
|
||||
|
||||
- 关联 Issue 自动发布: 每当有新的 Issue 创建时,Issue Linker Bot 会从历史 Issue 中找到最可能相关的问题,并自动在对应 Issue 中添加评论,标明相关的内容。这样,团队成员可以迅速了解当前工作的背景,避免重复劳动,并及时解决任务依赖。
|
||||
|
||||
- 基于深度学习模型的语义分析: Bot 采用了基于 ONNX 优化的深度学习模型来进行文本语义分析。该模型通过 Transformer 架构理解 Issue 的标题与描述,以推断不同 Issue 之间的潜在关系,包括任务的关联性、子任务关系、阻塞关系等。Bot 使用 HuggingFace 的 transformers 库加载经过优化的模型,在保证预测准确度的同时显著提升了推理速度。
|
||||
|
||||
- 无缝集成第三方项目平台: 通过对 GitLink 项目管理平台的集成,Issue Linker Bot 能够无缝地将分析结果发布到 GitLink 仓库中。无论您的团队是在使用 GitLink 进行项目管理,还是采用其他工作流,Bot 都能无缝接入您的流程,并自动添加相关的链接和评论。
|
||||
|
||||
## Bot链接
|
||||
|
||||
https://www.gitlink.org.cn/softbot/10038
|
||||
|
|
@ -0,0 +1,112 @@
|
|||
#!/usr/bin/python
|
||||
import sys
|
||||
import os
|
||||
import requests
|
||||
from flask import Flask, jsonify, request
|
||||
import json
|
||||
from flask_cors import CORS, cross_origin
|
||||
from pymongo import MongoClient
|
||||
from tld import tld_infer
|
||||
|
||||
# 创建Flask应用实例
|
||||
app = Flask(__name__)
|
||||
|
||||
# 创建MongoDB客户端实例,默认连接到本地MongoDB
|
||||
try:
|
||||
client = MongoClient("localhost", 27017, serverSelectionTimeoutMS=5000)
|
||||
client.server_info() # 获取服务器信息以检测连接是否成功
|
||||
except Exception as e:
|
||||
print(f"Error connecting to MongoDB: {e}")
|
||||
client = None
|
||||
|
||||
@app.route("/webhook", methods=["POST"])
|
||||
@cross_origin()
|
||||
def webhook():
|
||||
try:
|
||||
print("Received a webhook request.")
|
||||
|
||||
event_data = request.json
|
||||
# print("Event data:", event_data)
|
||||
|
||||
gitlink_token = 'bot的token' # 需要输入bottoken,要在平台申请
|
||||
|
||||
if not gitlink_token:
|
||||
raise ValueError("GitLink token not found in environment variables.")
|
||||
|
||||
# 根据您提供的数据结构进行调整
|
||||
if event_data.get('action') == 'opened' and 'issue' in event_data:
|
||||
print("Processing issue creation event.")
|
||||
issue_data = event_data['issue']
|
||||
project_data = event_data['project']
|
||||
|
||||
# 获取 owner 和 repo 名称
|
||||
owner_id = event_data.get('sender', {}).get('id', 'default_user_id')
|
||||
# print('\n owner_id: %s \n' % owner_id)
|
||||
owner_login = event_data.get('sender', {}).get('login', 'default_user')
|
||||
login = project_data.get('author', {}).get('login') # 动态获取作者的登录名
|
||||
repo_name = project_data['identifier']
|
||||
issue_index = issue_data['project_issues_index'] # 使用项目内的索引
|
||||
issue_title = issue_data['subject']
|
||||
issue_body = issue_data['description']
|
||||
|
||||
# 将 Issue 信息存入数据库
|
||||
db = client['BotDB']
|
||||
collection = db[repo_name.replace("/", "_")]
|
||||
collection.insert_one({
|
||||
"number": issue_index,
|
||||
"title": issue_title,
|
||||
"body": issue_body,
|
||||
})
|
||||
|
||||
issues_out = collection.find({"number": {"$ne": issue_index}})
|
||||
related_issues = tld_infer({"title": issue_title, "body": issue_body}, issues_out)
|
||||
# print("Related issues found:", related_issues)
|
||||
|
||||
if related_issues:
|
||||
comment_body = "以下是我找到的可能与此问题相关的 Issue:\n"
|
||||
for related in related_issues:
|
||||
comment_body += f"- Issue #{related['issue_num']}: {related['label']}\n"
|
||||
|
||||
headers = {
|
||||
'User-Agent': 'Mozilla/5.0',
|
||||
"Authorization": f"Bearer {gitlink_token}",
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
|
||||
# 构建正确的 API URL
|
||||
comment_url = f"https://www.gitlink.org.cn/api/v1/{login}/{repo_name}/issues/{issue_index}/journals.json"
|
||||
print("Attempting to post comment to:", comment_url)
|
||||
|
||||
# 构建请求的 payload
|
||||
payload = {
|
||||
"uid": id, #需要填写bot的id,在创立bot页面
|
||||
"notes": comment_body, # 评论内容
|
||||
"attachment_ids": [], # 无附件
|
||||
"receivers_login": [owner_login] # 使用用户的 `login` 作为标识符
|
||||
}
|
||||
|
||||
# 打印 payload 以进行调试
|
||||
print("Payload being sent:", payload)
|
||||
|
||||
# 发送请求 - 直接传递字典而不是字符串化的 JSON
|
||||
response = requests.post(comment_url, json=payload, headers=headers)
|
||||
# print("GitLink API response:", response.status_code, response.text)
|
||||
|
||||
return jsonify({"status": "success"}), 200
|
||||
|
||||
except Exception as e:
|
||||
print("Error:", e)
|
||||
return jsonify({"error": str(e)}), 500
|
||||
|
||||
|
||||
@app.route("/")
|
||||
def home():
|
||||
return "Welcome to the Issue Bot API"
|
||||
|
||||
@app.route("/webhook_test", methods=["GET"])
|
||||
def webhook_test():
|
||||
return "Webhook test endpoint reached successfully", 200
|
||||
|
||||
if __name__ == "__main__":
|
||||
# 使用 Flask 启动应用
|
||||
app.run(host="0.0.0.0", port=8345, debug=True)
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
# import sys
|
||||
# import time
|
||||
# import numpy as np
|
||||
|
||||
from pathlib import Path
|
||||
from pymongo.cursor import Cursor
|
||||
from transformers import pipeline, AutoTokenizer
|
||||
from optimum.onnxruntime import ORTModelForSequenceClassification
|
||||
|
||||
# 识别类型映射
|
||||
LABEL_MAPPING = {
|
||||
"LABEL_0": "Relate",
|
||||
"LABEL_1": "Subtask",
|
||||
"LABEL_2": "Clone",
|
||||
"LABEL_3": "Block",
|
||||
"LABEL_4": "Incorporate",
|
||||
"LABEL_5": "Duplicate",
|
||||
"LABEL_6": "Non-Link",
|
||||
"LABEL_7": "Follow",
|
||||
"LABEL_8": "Cause",
|
||||
}
|
||||
|
||||
# ONNX模型路径
|
||||
model_dir = Path("./models/onnx_opt")
|
||||
|
||||
# 加载ONNX模型与分词器
|
||||
model = ORTModelForSequenceClassification.from_pretrained(
|
||||
model_dir, provider="CPUExecutionProvider"
|
||||
)
|
||||
tokenizer = AutoTokenizer.from_pretrained(model_dir)
|
||||
|
||||
max_seq_len = 192 # 最大序列长度(和训练设置保持一致)
|
||||
|
||||
# 加载pipeline
|
||||
tld_pipe = pipeline(
|
||||
task="text-classification",
|
||||
model=model,
|
||||
tokenizer=tokenizer,
|
||||
truncation=True,
|
||||
max_length=max_seq_len,
|
||||
device=-1,
|
||||
)
|
||||
|
||||
max_char_len = 3647 # 每个Issue文本中的最大字符数(和训练设置保持一致)
|
||||
top_k = 2 # 预测概率最大的top-k个链接
|
||||
|
||||
|
||||
def tld_infer(issue_in: dict, issues_out: Cursor):
|
||||
"""
|
||||
识别Issue间链接
|
||||
|
||||
param issue_in: 待识别链接的Issue
|
||||
param issues_out: 候选Issues
|
||||
"""
|
||||
|
||||
tld_res = [] # 保存所有识别结果
|
||||
# 拼接Issue标题、描述文本
|
||||
issue_in_text: str = issue_in["title"] + ". " + issue_in["body"]
|
||||
issue_in_text = issue_in_text[:max_char_len].strip()
|
||||
|
||||
# todo 把循环改为tensor,并行执行
|
||||
for issue_out in issues_out:
|
||||
issue_out_text: str = issue_out["title"] + ". " + issue_out["body"]
|
||||
issue_out_text = issue_out_text[:max_char_len].strip()
|
||||
|
||||
# 执行tld推理
|
||||
one_tld_res = tld_pipe({"text": issue_in_text, "text_pair": issue_out_text})
|
||||
|
||||
one_tld_res["label"] = LABEL_MAPPING[one_tld_res["label"]] # 转换识别类型
|
||||
# 识别类型为 `Non-Link`,跳过
|
||||
if one_tld_res["label"] == "Non-Link":
|
||||
continue
|
||||
|
||||
one_tld_res["issue_num"] = issue_out["number"] # 添加识别的Issue编号
|
||||
tld_res.append(one_tld_res)
|
||||
|
||||
# 按预测概率排序,返回top-k个(注意:总的识别链接数可能小于k)链接
|
||||
tld_res = sorted(tld_res, key=lambda x: x["score"], reverse=True)
|
||||
return tld_res[:top_k]
|
||||
Loading…
Reference in New Issue