generated from Debdut/browser-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
96b3d84
commit bb26797
Showing
11 changed files
with
178 additions
and
367 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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,85 @@ | ||
import { JiraCredentialStore, JiraCredentials } from './settings'; | ||
|
||
export class JiraIssue { | ||
constructor(init?: Partial<JiraIssue>) { | ||
Object.assign(this, init); | ||
} | ||
|
||
key!: string; | ||
summary!: string; | ||
assignee!: string; | ||
} | ||
|
||
export class JiraIssueRetriever { | ||
private Credentials: JiraCredentials | null = null; | ||
|
||
async init(): Promise<void> { | ||
this.Credentials = await JiraCredentialStore.load(); | ||
|
||
if (!this.Credentials) { | ||
throw new Error('Jira credentials not found'); | ||
} | ||
} | ||
|
||
async searchIssues(jql: string, startAt: number) : Promise<{issues: JiraIssue[], total: number}> { | ||
if (!this.Credentials) { | ||
throw new Error('Not initialized'); | ||
} | ||
|
||
const params = { | ||
'jql': jql, | ||
'fields': 'summary,description,assignee', | ||
'startAt': startAt.toString(), | ||
'maxResults': '100', | ||
} | ||
|
||
var url = new URL(this.Credentials.instanceUrl + '/rest/api/3/search'); | ||
url.search = new URLSearchParams(params).toString(); | ||
|
||
const response = await fetch(url.toString(), { | ||
method: 'GET', | ||
headers: { | ||
'Authorization': `Basic ${btoa(`${this.Credentials.username}:${this.Credentials.apiToken}`)}`, | ||
'Accept': 'application/json', | ||
} | ||
}); | ||
|
||
if (!response.ok) { | ||
throw new Error(`Failed to fetch issues: ${response.statusText}`); | ||
} | ||
|
||
const rawIssueResponse = await response.json(); | ||
|
||
console.log(rawIssueResponse); | ||
|
||
const rawIssues = rawIssueResponse.issues; | ||
const issues = rawIssues.map((rawIssue: any) => { | ||
return new JiraIssue({ | ||
key: rawIssue.key, | ||
summary: rawIssue.fields.summary, | ||
assignee: rawIssue.fields.assignee?.displayName || '', | ||
}); | ||
}); | ||
|
||
return { issues: issues, total: rawIssueResponse.total }; | ||
} | ||
|
||
async getRecentlyUpdatedIssues(): Promise<JiraIssue[]> { | ||
if (!this.Credentials) { | ||
throw new Error('Not initialized'); | ||
} | ||
|
||
const query = 'updated >= -30d order by updated DESC'; | ||
|
||
const initialResults = await this.searchIssues(query, 0); | ||
const total = initialResults.total; | ||
var issues = initialResults.issues; | ||
|
||
while (issues.length < total) { | ||
const nextResults = await this.searchIssues(query, issues.length); | ||
issues = issues.concat(nextResults.issues); | ||
} | ||
|
||
return issues; | ||
} | ||
} |
This file contains 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 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 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 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 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,12 @@ | ||
.autocomplete-entry { | ||
background-color: #FFFFFF; | ||
padding: 5px; | ||
} | ||
|
||
.autocomplete-entry.selected { | ||
background-color: #009ceb; | ||
} | ||
|
||
.autocomplete-entry:hover { | ||
background-color: #cbd1d3; | ||
} |
This file contains 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
Empty file.
This file was deleted.
Oops, something went wrong.