Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions src/atlclients/authStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ import {
import { Negotiator } from './negotiate';
import { OAuthRefesher } from './oauthRefresher';

function isAtlassianCloud(site: DetailedSiteInfo): boolean {
return site.host.endsWith('.atlassian.net') || site.host.endsWith('.jira.com');
}

const keychainServiceNameV3 = version.endsWith('-insider') ? 'atlascode-insiders-authinfoV3' : 'atlascode-authinfoV3';

enum Priority {
Expand Down Expand Up @@ -87,7 +91,7 @@ export class CredentialManager implements Disposable {

public async checkScopes(site: DetailedSiteInfo, scopes: string[]): Promise<CheckedScopes | undefined> {
// Scopes are only applicable to cloud sites
if (!site.host.endsWith('.atlassian.net')) {
if (!isAtlassianCloud(site)) {
return undefined;
}

Expand Down Expand Up @@ -120,7 +124,7 @@ export class CredentialManager implements Disposable {

async getApiTokenIfExists(site: DetailedSiteInfo): Promise<BasicAuthInfo | undefined> {
// Only applicable to cloud sites
if (!site.host.endsWith('.atlassian.net')) {
if (!isAtlassianCloud(site)) {
return undefined;
}

Expand All @@ -144,24 +148,22 @@ export class CredentialManager implements Disposable {
async findApiTokenForSite(site?: DetailedSiteInfo | string): Promise<BasicAuthInfo | undefined> {
const siteToCheck = typeof site === 'string' ? Container.siteManager.getSiteForId(ProductJira, site) : site;

if (!siteToCheck || !siteToCheck.host.endsWith('.atlassian.net')) {
if (!siteToCheck || !isAtlassianCloud(siteToCheck)) {
return undefined;
}

const sites = Container.siteManager.getSitesAvailable(ProductJira);
const selectedSiteEmail = (await this.getAuthInfo(siteToCheck))?.user.email;

// For a cloud site - check if we have another cloud site with the same user and API key
const promises = sites
.filter((site) => site.host.endsWith('.atlassian.net'))
.map(async (site) => {
const authInfo = await this.getAuthInfo(site);
if (authInfo?.user.email === selectedSiteEmail && isBasicAuthInfo(authInfo)) {
// There's another site with the same user and cloud, so we can use that API key for suggestions
return authInfo as BasicAuthInfo;
}
return undefined;
});
const promises = sites.filter(isAtlassianCloud).map(async (site) => {
const authInfo = await this.getAuthInfo(site);
if (authInfo?.user.email === selectedSiteEmail && isBasicAuthInfo(authInfo)) {
// There's another site with the same user and cloud, so we can use that API key for suggestions
return authInfo as BasicAuthInfo;
}
return undefined;
});

const results = await Promise.all(promises);
return results.find((authInfo) => authInfo !== undefined);
Expand Down
2 changes: 1 addition & 1 deletion src/rovo-dev/rovoDevChatContextProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class RovoDevChatContextProvider {
// search for a Jira work item
if (dragDropData.find((x) => x.includes('atlascode.views.jira.assignedWorkItemsTreeView'))) {
const uri = URL.parse(dragDropData[0] || dragDropData[1]);
if (uri?.hostname.endsWith('.atlassian.net')) {
if (uri?.hostname.endsWith('.atlassian.net') || uri?.hostname.endsWith('.jira.com')) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why doesn't this make use of the function?

const urlString = uri.toString();
await this.addContextItem({
contextType: 'jiraWorkItem',
Expand Down
Loading