Skip to content

Commit

Permalink
feat: update prompt specify github issue + create issue with title, d…
Browse files Browse the repository at this point in the history
…escription
  • Loading branch information
FlorentLvr committed Feb 15, 2024
1 parent 831598b commit 007992f
Show file tree
Hide file tree
Showing 2 changed files with 361 additions and 190 deletions.
207 changes: 17 additions & 190 deletions models/operations-engine/core/tools/GitHub_Create_Issue.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,9 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"id": "cc038b10-2679-42bc-909e-09a298339df4",
"metadata": {
"execution": {
"iopub.execute_input": "2024-02-07T12:03:50.605458Z",
"iopub.status.busy": "2024-02-07T12:03:50.605009Z",
"iopub.status.idle": "2024-02-07T12:03:52.756372Z",
"shell.execute_reply": "2024-02-07T12:03:52.755754Z",
"shell.execute_reply.started": "2024-02-07T12:03:50.605364Z"
},
"papermill": {},
"tags": []
},
Expand All @@ -132,38 +125,29 @@
},
"source": [
"### Setup variables\n",
"- `repo_url`: https://github.com/jupyter-naas/awesome-notebooks\n",
"- `title`: My New Issue\n",
"- `description`: My Description\n",
"- `assignee`: \"Abi\"\n",
"- `label`: \"good first issue\", \"enhancement\"\n",
"- `repo_url`: https://github.com/jupyter-naas/awesome-notebooks\n",
"- `token`: \"gitwxxxxxxxxxxxxxxx\"\n",
"- `body`: This variable stores the body to be send by the webhook."
]
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"id": "6cf9bd9b-ce83-45a5-ab0f-15c978458b42",
"metadata": {
"execution": {
"iopub.execute_input": "2024-02-07T12:03:52.757879Z",
"iopub.status.busy": "2024-02-07T12:03:52.757655Z",
"iopub.status.idle": "2024-02-07T12:03:52.761294Z",
"shell.execute_reply": "2024-02-07T12:03:52.760718Z",
"shell.execute_reply.started": "2024-02-07T12:03:52.757851Z"
},
"papermill": {},
"tags": []
},
"outputs": [],
"source": [
"# Mandatory\n",
"repo_url = \"https://github.com/jupyter-naas/awesome-notebooks\"\n",
"title = \"My New Issue\"\n",
"description = \"My Description\"\n",
"assignee = None\n",
"label = None\n",
"repo_url = \"https://github.com/jupyter-naas/awesome-notebooks\"\n",
"token = None\n",
"\n",
"# Optional\n",
Expand Down Expand Up @@ -195,16 +179,9 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"id": "9bf914f6-f343-4764-ab2c-8f04b317f257",
"metadata": {
"execution": {
"iopub.execute_input": "2024-02-07T12:03:52.762642Z",
"iopub.status.busy": "2024-02-07T12:03:52.762262Z",
"iopub.status.idle": "2024-02-07T12:03:52.861395Z",
"shell.execute_reply": "2024-02-07T12:03:52.860837Z",
"shell.execute_reply.started": "2024-02-07T12:03:52.762612Z"
},
"papermill": {},
"tags": [
"parameters"
Expand All @@ -217,8 +194,6 @@
" repo_url = body.get(\"repo_url\")\n",
" title = body.get(\"title\")\n",
" description = body.get(\"description\")\n",
" assignee = body.get(\"assignee\")\n",
" label = body.get(\"label\")\n",
" token = body.get(\"token\")"
]
},
Expand Down Expand Up @@ -246,46 +221,30 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"id": "fa1e9e64-09c4-449f-8ddd-d55f4c064eed",
"metadata": {
"execution": {
"iopub.execute_input": "2024-02-07T12:03:52.862701Z",
"iopub.status.busy": "2024-02-07T12:03:52.862358Z",
"iopub.status.idle": "2024-02-07T12:03:53.108878Z",
"shell.execute_reply": "2024-02-07T12:03:53.107884Z",
"shell.execute_reply.started": "2024-02-07T12:03:52.862670Z"
},
"papermill": {},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Status: ok\n",
"Message: ❌ Unable to Connect to GitHub. Issue not created: 'My New Issue'\n"
]
}
],
"outputs": [],
"source": [
"def create_new_github_issue(\n",
" repo_url=None,\n",
" title=None,\n",
" description=None,\n",
" assignee=None,\n",
" label=None,\n",
" token=None\n",
"): \n",
" # Init\n",
" status = \"ok\"\n",
" message = f\"✅ Issue has been created, here is the link: [URL]\"\n",
" \n",
" # Check if GitHub connection is set\n",
" if not naas.secret.get('GITHUB_TOKEN'):\n",
" if not token and not naas.secret.get('GITHUB_TOKEN'):\n",
" message = f\"❌ Unable to Connect to GitHub. Issue not created: '{title}'\"\n",
" return status, message \n",
" elif not token and naas.secret.get('GITHUB_TOKEN'):\n",
" token = naas.secret.get('GITHUB_TOKEN')\n",
" \n",
" # Create Issue\n",
" try:\n",
Expand All @@ -299,32 +258,24 @@
" data[\"title\"] = title\n",
" if description:\n",
" data[\"body\"] = description\n",
" if assignee:\n",
" data[\"assignees\"] = assignee\n",
" if label:\n",
" data[\"labels\"] = label\n",
" if len(data) > 0:\n",
" headers = {'Authorization': f'token {token}'}\n",
" response = requests.post(url, data=json.dumps(data), headers=headers)\n",
" github_issue = response.json()\n",
" url = f\"https://github.com/jupyter-naas/awesome-notebooks/issues/{github_issue.get('number')}\"\n",
" url = f\"{repo_url}/issues/{github_issue.get('number')}\"\n",
" message = message.replace(\"[URL]\", url)\n",
" else:\n",
" message = f\"Nothing to create, payload is empty: {data}.\"\n",
" message = f\"Nothing to create, payload is empty: {data}.\"\n",
" except Exception as e:\n",
" status = \"ko\"\n",
" message = e\n",
" print(e)\n",
" return status, message\n",
"\n",
"\n",
"\n",
"status, message = create_new_github_issue(\n",
" repo_url,\n",
" title,\n",
" description,\n",
" assignee,\n",
" label,\n",
" token\n",
")\n",
"print(\"Status:\", status)\n",
Expand Down Expand Up @@ -355,95 +306,10 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"id": "a1b08bd9-fee4-403e-871e-3c797d07e4ec",
"metadata": {
"execution": {
"iopub.execute_input": "2024-02-07T12:03:53.110176Z",
"iopub.status.busy": "2024-02-07T12:03:53.109926Z",
"iopub.status.idle": "2024-02-07T12:03:53.698703Z",
"shell.execute_reply": "2024-02-07T12:03:53.697999Z",
"shell.execute_reply.started": "2024-02-07T12:03:53.110146Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"👌 Well done! Your Notebook has been sent to production.\n",
"\n"
]
},
{
"data": {
"application/javascript": [
"\n",
" if (!window.copyToClipboard) {\n",
" window.copyToClipboard = (text) => {\n",
" const dummy = document.createElement(\"textarea\");\n",
" document.body.appendChild(dummy);\n",
" dummy.value = text;\n",
" dummy.select();\n",
" document.execCommand(\"copy\");\n",
" document.body.removeChild(dummy);\n",
" }\n",
" }\n",
" "
],
"text/plain": [
"<IPython.core.display.Javascript object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "fe930e1a188d4979961a1090e60c2708",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Button(button_style='primary', description='Copy URL', style=ButtonStyle())"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "20999fd3d7914af089085718c93a1cbb",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Output()"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"PS: to remove the \"Notebook as API\" feature, just replace .add by .delete\n"
]
},
{
"data": {
"text/plain": [
"'https://public.naas.ai/YWJpLTJEZGVtby00MG5hYXMtMkVhaQ==/notebook/7501dea41c95dbb1c493d30830442aca69aff6a7f029a032374026e6ca32'"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"metadata": {},
"outputs": [],
"source": [
"naas.webhook.add()"
]
Expand All @@ -469,52 +335,13 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"id": "c0b8c592-9706-4f53-aaa9-c87bf4fc6d75",
"metadata": {
"execution": {
"iopub.execute_input": "2024-02-07T12:03:53.700302Z",
"iopub.status.busy": "2024-02-07T12:03:53.700040Z",
"iopub.status.idle": "2024-02-07T12:03:53.710351Z",
"shell.execute_reply": "2024-02-07T12:03:53.709741Z",
"shell.execute_reply.started": "2024-02-07T12:03:53.700270Z"
},
"papermill": {},
"tags": []
},
"outputs": [
{
"data": {
"text/markdown": [
"Response Set as JSON, preview below: "
],
"text/plain": [
"<IPython.core.display.Markdown object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/json": {
"message": "❌ Unable to Connect to GitHub. Issue not created: 'My New Issue'",
"status": "ok"
},
"text/plain": [
"<IPython.core.display.JSON object>"
]
},
"metadata": {
"application/json": {
"expanded": false,
"naas_api": true,
"root": "root"
}
},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"naas.webhook.respond_json(\n",
" {\n",
Expand Down
Loading

0 comments on commit 007992f

Please sign in to comment.