Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Extract Excel from Compass

Nicolò Spito September 13, 2024

 

For audit reason we need to download all the components of our Atlassian Compass.

Is it possibile to extract in Excel all the Components with last updates date?

2 answers

1 accepted

1 vote
Answer accepted
Kelvin T
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 13, 2024

Hello @Nicolò Spito

I hope this message finds you well. My name is Kelvin, and I’m with the Compass Support Team.

At this time, Compass does not offer a native feature to export components to a CSV file. However, you can use the Python script below to generate a CSV file with your Compass components.

Please note that this script was not developed by Atlassian and is therefore not officially supported. We recommend reviewing it carefully before running it.

import base64
import json
import requests
import csv

# Define your variables here
cloudId = "Your-cloudID"
api_token = "Your-API-TOKEN"
email = "Email"

# Adjust the query to use the cloudId variable
query = f"""
query MyQuery {{
  compass {{
    searchComponents(cloudId: "{cloudId}", query: {{first: 10}}) {{
      ... on CompassSearchComponentConnection {{
        edges {{
          cursor
          node {{
            component {{
              name
              typeId
              description
              labels {{
                name
              }}
              links {{
                url
              }}
              ownerId
              applicableScorecards {{
                componentTiers {{
                  value
                }}
              }}
            }}
          }}
        }}
        totalCount
      }}
    }}
  }}
}}
"""

url = "https://api.atlassian.com/graphql"
auth_header = f"{email}:{api_token}"
encoded_auth_header = base64.b64encode(auth_header.encode('utf-8')).decode('utf-8')
headers = {
    "Content-Type": "application/json",
    "Accept": "application/json",
    "Authorization": f"Basic {encoded_auth_header}",
    "X-ExperimentalApi": "compass-beta"
}
request_data = {
    "query": query,
}

response = requests.post(url, headers=headers, json=request_data)
response_data = json.loads(response.text)

# Extract the component data
components = response_data.get('data', {}).get('compass', {}).get('searchComponents', {}).get('edges', [])

# Define the CSV filename
csv_filename = 'components.csv'

# Write the data to a CSV file
with open(csv_filename, mode='w', newline='') as csv_file:
    fieldnames = ['name', 'type', 'description', 'labels', 'links', 'owner team', 'applicable scorecards']
    writer = csv.DictWriter(csv_file, fieldnames=fieldnames)
    writer.writeheader()

    for component in components:
        node = component.get('node', {})
        component_data = node.get('component', {})
        writer.writerow({
            'name': component_data.get('name', ''),
            'type': component_data.get('typeId', ''),
            'description': component_data.get('description', ''),
            'labels': ', '.join([label.get('name', '') for label in component_data.get('labels', [])]),
            'links': ', '.join([link.get('url', '') for link in component_data.get('links', [])]),
            'owner team': component_data.get('ownerId', ''),
            'applicable scorecards': ', '.join([str(tier.get('value', '')) for scorecard in component_data.get('applicableScorecards', []) for tier in scorecard.get('componentTiers', [])])
        })

print(f"Data exported to '{csv_filename}'")

 

Guy Derriman September 15, 2024

Hi Kevin 
Thanks for your snippet here it's very handy 
I have for the life of me not been able to get the value of a CustomField or a Field element 
Can you please update your query to provide a sample of this?
Component > CustomFields yields CompassCustomField which have implmentations like CompassCustomTextField that have textValue but I cant work out how to access it. Do I need to cast??

Like Steffen Opel _Utoolity_ likes this
1 vote
Sebastian Hesse September 13, 2024

As far as I know, this is not possible (yet?). I guess you want some sort of CSV file that contains all your components with certain fields and then edit/open this file with Excel, right? With a similar (or same) structure like the CSV import from this documentation page ?

Edit: Haven’t seen the other answer before posting 😀

Nicolò Spito September 15, 2024

Mainly for audit reason or to underlight the components that need update from the owners.

Like Steffen Opel _Utoolity_ likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events