async collectData()

in plugins/soundcheck-backend-module-branch/src/branchcount.ts [139:179]


  async collectData(entity: Entity, factRef: string) {
    const entityRef = stringifyEntityRef(entity);
    const entityScmUrl = getEntityScmUrl(entity);
    const gitUrl = parseGitUrl(entityScmUrl);

    const { token } = await this.#credentialsProvider.getCredentials({
      url: entityScmUrl,
    });
    try {
      const {
        repository: { refs: totalCount },
      } = await graphql<GraphQlQueryResponseData>(
        `
          query numBranches($owner: String!, $repo: String!) {
            repository(owner: $owner, name: $repo) {
              refs(first: 0, refPrefix: "refs/heads/") {
                totalCount
              }
            }
          }
        `,
        {
          owner: gitUrl.owner,
          repo: gitUrl.name,
          headers: {
            authorization: `Bearer ${token}`,
          },
        },
      );
      this.#logger.info(
        `BranchCountFactCollector: ${gitUrl.owner} ${gitUrl.name} - Total Count: ${totalCount} `,
      );

      return this.buildFact(entityRef, factRef, totalCount);
    } catch (e) {
      this.#logger.error(
        `BranchCountFactCollector: ${gitUrl.owner} ${gitUrl.name} - Failed to collect branch data with error: ${e}`,
      );
      return null;
    }
  }