-
Notifications
You must be signed in to change notification settings - Fork 181
feature/azure devops integration #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
WilsonCodeSpace
wants to merge
13
commits into
GerevAI:main
Choose a base branch
from
WilsonCodeSpace:feature/azure-devops-integration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 10 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3c17cd3
Azure DevOps Work Item Integration
WilsonCodeSpace 5048353
Add Docs
WilsonCodeSpace 8dcce0a
Update google_drive.py
teynar c8ed67a
Merge pull request #65 from teynar/fix/missing-photoLink-field
Roey7 9f47395
add missing persistqueue dependency
teynar 711610d
Merge pull request #66 from teynar/patch-1
Roey7 70e454a
Add Docs
WilsonCodeSpace a853b6c
Rebase
WilsonCodeSpace f82e95f
Merge branch 'feature/azure-devops-integration' of https://github.com…
WilsonCodeSpace 59db58d
Move Config Strip
WilsonCodeSpace 659d6de
Adjust Display Name
WilsonCodeSpace 6dc2224
Update azuredevops.py
WilsonCodeSpace 16ef826
Remove Import
WilsonCodeSpace File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,4 +19,5 @@ venv | |
.*.sw? | ||
|
||
|
||
.env | ||
.env | ||
.DS_Store |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import datetime | ||
import logging | ||
from typing import Dict, List | ||
import requests | ||
import base64 | ||
import urllib.parse | ||
from dataclasses import dataclass | ||
|
||
from azure.devops.connection import Connection | ||
from msrest.authentication import BasicAuthentication | ||
|
||
from data_source_api.base_data_source import BaseDataSource, ConfigField, HTMLInputType | ||
from data_source_api.basic_document import DocumentType, BasicDocument | ||
from data_source_api.exception import InvalidDataSourceConfig | ||
from index_queue import IndexQueue | ||
from pydantic import BaseModel | ||
from parsers.html import html_to_text | ||
from data_source_api.utils import parse_with_workers | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
@dataclass | ||
class DevOpsConfig(): | ||
organization_url: str | ||
access_token: str | ||
project_name: str | ||
query_id: str | ||
|
||
def __post_init__(self): | ||
self.query_id = self.query_id.strip() | ||
self.access_token = self.access_token.strip() | ||
self.project_name = self.project_name.strip() | ||
self.organization_url = self.organization_url.strip() | ||
|
||
class AzuredevopsDataSource(BaseDataSource): | ||
@staticmethod | ||
def get_config_fields() -> List[ConfigField]: | ||
return [ | ||
ConfigField(label="AzureDevOps organization URL", placeholder="https://dev.azure.com/org", name="organization_url"), | ||
ConfigField(label="Personal Access Token", name="access_token", type=HTMLInputType.PASSWORD), | ||
ConfigField(label="Project Name", name="project_name"), | ||
ConfigField(label="Query ID", name="query_id"), | ||
] | ||
|
||
@staticmethod | ||
def validate_config(config: Dict) -> None: | ||
try: | ||
devops_config = DevOpsConfig(**config) | ||
credentials = BasicAuthentication('', devops_config.access_token) | ||
connection = Connection(base_url=devops_config.organization_url, creds=credentials) | ||
core_client = connection.clients.get_core_client() | ||
core_client.get_projects() | ||
except Exception as e: | ||
raise InvalidDataSourceConfig from e | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self._config['devops_config'] = DevOpsConfig(**self._config) | ||
credentials = BasicAuthentication('', self._config['devops_config'].access_token) | ||
connection = Connection(base_url=self._config['devops_config'].organization_url, creds=credentials) | ||
self._work_item_tracking_client = connection.clients.get_work_item_tracking_client() | ||
|
||
def _parse_documents_worker(self, raw_docs: List[Dict]): | ||
logging.info(f'Worker parsing {len(raw_docs)} documents') | ||
parsed_docs = [] | ||
total_fed = 0 | ||
for item in raw_docs: | ||
for raw_page in item['comments']: | ||
create_date = datetime.datetime.strptime(raw_page['createdDate'], "%Y-%m-%dT%H:%M:%S.%fZ") | ||
if create_date < self._last_index_time: | ||
continue | ||
author = raw_page['createdBy']['displayName'] | ||
workitem_id = raw_page['workItemId'] | ||
title = str(raw_page['workItemId']) + ' - ' + raw_page['createdBy']['displayName'] | ||
html_content = raw_page['text'] | ||
plain_text = html_to_text(html_content) | ||
author_image_url = raw_page['createdBy']['_links']['avatar']['href'] | ||
url = f"{self._config['devops_config'].organization_url}/{urllib.parse.quote(self._config['devops_config'].project_name)}/_workitems/edit/{raw_page['workItemId']}".strip() | ||
|
||
parsed_docs.append(BasicDocument( | ||
id=workitem_id, | ||
data_source_id=self._data_source_id, | ||
author=author, | ||
author_image_url=author_image_url, | ||
content=plain_text, | ||
type=DocumentType.COMMENT, | ||
title=title, | ||
timestamp=create_date, | ||
location=self._config['devops_config'].project_name, | ||
url=url | ||
)) | ||
|
||
if len(parsed_docs) >= 50: | ||
total_fed += len(parsed_docs) | ||
IndexQueue.get_instance().put(docs=parsed_docs) | ||
parsed_docs = [] | ||
|
||
IndexQueue.get_instance().put(docs=parsed_docs) | ||
total_fed += len(parsed_docs) | ||
if total_fed > 0: | ||
logging.info(f'Worker fed {total_fed} documents') | ||
|
||
|
||
def _list_work_item_comments(self, work_item_url) -> List[Dict]: | ||
authorization = str(base64.b64encode(bytes(':'+self._config['devops_config'].access_token, 'ascii')), 'ascii') | ||
headers = { | ||
'Accept': 'application/json', | ||
'Authorization': 'Basic '+authorization | ||
} | ||
return requests.get(url=work_item_url + '/comments', headers=headers).json() | ||
|
||
def _feed_new_documents(self) -> None: | ||
logger.info('Feeding new Azure DevOps Work Items') | ||
raw_docs = [] | ||
work_item_results = self._work_item_tracking_client.query_by_id(self._config['devops_config'].query_id) | ||
for work_item in work_item_results.work_items: | ||
result = self._list_work_item_comments(work_item.url) | ||
if result['totalCount'] > 0: | ||
raw_docs.append(result) | ||
parse_with_workers(self._parse_documents_worker, raw_docs) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,5 @@ python-pptx | |
alembic | ||
rocketchat-API | ||
mattermostdriver | ||
persistqueue | ||
azure-devops |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Setting up Azure DevOps Data Source | ||
Please note this will only index Work Items returned by your Query | ||
|
||
1. Navigate to the settings menu in the top-right hand corner of the screen and select Personal Access Tokens. | ||
 | ||
2. Click on the new option. | ||
 | ||
1. Complete the form, and set the expiration date to custom. Select the furthest expiration date possible. Make sure to only provide read only permissions. | ||
 | ||
1. Hit Create and copy the token from the next window. | ||
2. Navigate to your Project and go to Boards > Queries. Select your query from the list. | ||
 | ||
1. Copy the Query ID from the URL in the address bar. | ||
 | ||
1. Go to Gerev and input all of the data into the fields. | ||
 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.