Skip to content
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

Error: Failed to find api location for area: Location id: e81700f7-3be2-46de-8624-2eb35882fcaa #581

Closed
lintaonz opened this issue Jan 28, 2024 · 1 comment

Comments

@lintaonz
Copy link

Environment

Node version: v20.10.0
Npm version: 10.2.3
OS and version: macOS 13.6.3
azure-devops-node-api version: 12.3.0

Issue Description

I am using Azure DevOps free plan. I have create a PAT with full access.

When I try to create a getAPI object with connection.getGitApi() , it returns an error.

Here is my code:

export const commentOnPR = async (
  comment: string
): Promise<void> => {
  console.log(comment);

  try {
    const { organization, azureToken, pullRequestId, repositoryId, project } =
      gitAzureEnvVariables();

    // your collection url
    const orgUrl = `https://dev.azure.com/${organization}/`;
    const pullRequestIdNumber = Number(pullRequestId);

    console.log({ organization, azureToken, pullRequestId, repositoryId, project });

    const authHandler = azdev.getPersonalAccessTokenHandler(azureToken); // The PAT has Full permissions
    console.log('authHandler', authHandler);
    const connection = new azdev.WebApi(orgUrl, authHandler);
    console.log('connection', connection);

    const gitApiObject: gitApiObject.IGitApi = await connection.getGitApi();  // the error throw form this line

    const repos: GitInterfaces.GitRepository[] = await gitApiObject.getRepositories(project);
    console.log("There are", repos.length, "repositories in this project");
    
    const threads: GitInterfaces.GitPullRequestCommentThread[] =
      await gitApiObject.getThreads(repositoryId, pullRequestIdNumber, project);
    console.log('threads', threads);
    const prComment: GitInterfaces.Comment = <GitInterfaces.Comment>{
      content: comment,
    };

    // createComment(comment: GitInterfaces.Comment, repositoryId: string, pullRequestId: number, threadId: number, project?: string): Promise<GitInterfaces.Comment>;
    await gitApiObject.createComment(
      prComment,
      repositoryId,
      pullRequestIdNumber,
      threads[0].id || 0,
      project
    );
  } catch (error) {
    console.log(error);
    logger.error(`Failed to comment on PR: ${JSON.stringify(error)}`);
    throw error;    
  }

Expected behaviour

It should create a comment for the specific PR

Actual behaviour

Error: Failed to find api location for area: Location id: e81700f7-3be2-46de-8624-2eb35882fcaa

Logs

Error: Failed to find api location for area: Location id: e81700f7-3be2-46de-8624-2eb35882fcaa
    at code-review-gpt/packages/code-review-gpt/node_modules/azure-devops-node-api/VsoClient.js:85:23
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
@lintaonz
Copy link
Author

I found the issue. The issue is caused by the incorrect organization. Once I fix it. Everything works fine.

const orgUrl = https://dev.azure.com/${organization}/;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant