src/asana_client.py
def create_project(self, linear_project: LinearProject, squad_portfolio_gid: str) -> AsanaProject:
        """Create Asana project from linear project values"""

        linear_project_url = f"https://linear.app/gorgias/project/{linear_project['slugId']}"
        team_name = current_app.config["LINEAR_TEAMS"][linear_project["team"]["id"]]

        asana_project = {
            "name": linear_project["name"],
            "notes": f"Linear URL: {linear_project_url}\n{linear_project['description']}",
            "team": current_app.config["ASANA_TEAMS"][team_name],
        }

        current_app.logger.debug(f"creating project {asana_project['name']}")
        asana_project = self.client.projects.create_project(asana_project)

        # We can only add certain fields (ex: a custom field) to the project once it was added to the portfolio

        # add project to portfolio
        current_app.logger.debug(f"adding item to portfolio {squad_portfolio_gid}")
        self.client.portfolios.add_item_for_portfolio(
            squad_portfolio_gid,
            {"item": asana_project["gid"]},
        )

        # Add custom fields for the project
        for custom_field_label, custom_field_id in current_app.config["ASANA_PROJECTS_CUSTOM_FIELDS"].items():
            current_app.logger.debug(f"adding custom field to project {custom_field_label}")
            self.client.projects.add_custom_field_setting_for_project(
                asana_project["gid"], {"custom_field": custom_field_id}
            )

        asana_project_update = {
            "custom_fields": {
                current_app.config["ASANA_PROJECTS_CUSTOM_FIELDS"][
                    AsanaCustomFieldLabels.LINEAR_URL
                ]: linear_project_url,
                # For some reason portfolios in Asana doesn't display the teams values on projects.
                # Instead we have to use a custom field for the team
                current_app.config["ASANA_PROJECTS_CUSTOM_FIELDS"][AsanaCustomFieldLabels.TEAM]: current_app.config[
                    "ASANA_CUSTOM_FIELD_TEAM_ENUM_VALUES"
                ][team_name],
            }
        }
        current_app.logger.debug(f"updating project {asana_project['name']}")
        self.client.projects.update_project(asana_project["gid"], asana_project_update)

        # Add initial members to created project
        new_members = {
            "members": current_app.config["ASANA_PORTFOLIO_USERS_IDS"],
        }
        asana_project = self.client.projects.add_members_for_project(asana_project["gid"], new_members)

        current_app.logger.info(f"Asana project created: {asana_project['name']}")

        # fetch the project again with the latest fields
        current_app.logger.debug(f"re-fetching project: {asana_project['name']}")
        asana_project = self.client.projects.get_project(asana_project["gid"])
        current_app.logger.debug(f"project fetched: {asana_project}")
        return asana_project
Create Asana project from linear project values
Create Asana project from linear project values
Create Asana project from linear project values
def create_project(self, linear_project: LinearProject, squad_portfolio_gid: str) -> AsanaProject:
        linear_project_url = f"https://linear.app/gorgias/project/{linear_project['slugId']}"
        team_name = current_app.config["LINEAR_TEAMS"][linear_project["team"]["id"]]
        asana_project = {
            "name": linear_project["name"],
            "notes": f"Linear URL: {linear_project_url}\n{linear_project['description']}",
            "team": current_app.config["ASANA_TEAMS"][team_name],
        }
        current_app.logger.debug(f"creating project {asana_project['name']}")
        asana_project = self.client.projects.create_project(asana_project)
        current_app.logger.debug(f"adding item to portfolio {squad_portfolio_gid}")
        self.client.portfolios.add_item_for_portfolio(
            squad_portfolio_gid,
            {"item": asana_project["gid"]},
        )
        for custom_field_label, custom_field_id in current_app.config["ASANA_PROJECTS_CUSTOM_FIELDS"].items():
            current_app.logger.debug(f"adding custom field to project {custom_field_label}")
            self.client.projects.add_custom_field_setting_for_project(
                asana_project["gid"], {"custom_field": custom_field_id}
            )
        asana_project_update = {
            "custom_fields": {
                current_app.config["ASANA_PROJECTS_CUSTOM_FIELDS"][
                    AsanaCustomFieldLabels.LINEAR_URL
                ]: linear_project_url,
                current_app.config["ASANA_PROJECTS_CUSTOM_FIELDS"][AsanaCustomFieldLabels.TEAM]: current_app.config[
                    "ASANA_CUSTOM_FIELD_TEAM_ENUM_VALUES"
                ][team_name],
            }
        }
        current_app.logger.debug(f"updating project {asana_project['name']}")
        self.client.projects.update_project(asana_project["gid"], asana_project_update)
        new_members = {
            "members": current_app.config["ASANA_PORTFOLIO_USERS_IDS"],
        }
        asana_project = self.client.projects.add_members_for_project(asana_project["gid"], new_members)
        current_app.logger.info(f"Asana project created: {asana_project['name']}")
        current_app.logger.debug(f"re-fetching project: {asana_project['name']}")
        asana_project = self.client.projects.get_project(asana_project["gid"])
        current_app.logger.debug(f"project fetched: {asana_project}")
        return asana_project
def create_project ( self , linear_project : LinearProject , squad_portfolio_gid : str ) -> AsanaProject : linear_project_url = f"https://linear.app/gorgias/project/{linear_project['slugId']}" team_name = current_app . config [ "LINEAR_TEAMS" ] [ linear_project [ "team" ] [ "id" ] ] asana_project = { "name" : linear_project [ "name" ] , "notes" : f"Linear URL: {linear_project_url}\n{linear_project['description']}" , "team" : current_app . config [ "ASANA_TEAMS" ] [ team_name ] , } current_app . logger . debug ( f"creating project {asana_project['name']}" ) asana_project = self . client . projects . create_project ( asana_project ) current_app . logger . debug ( f"adding item to portfolio {squad_portfolio_gid}" ) self . client . portfolios . add_item_for_portfolio ( squad_portfolio_gid , { "item" : asana_project [ "gid" ] } , ) for custom_field_label , custom_field_id in current_app . config [ "ASANA_PROJECTS_CUSTOM_FIELDS" ] . items ( ) : current_app . logger . debug ( f"adding custom field to project {custom_field_label}" ) self . client . projects . add_custom_field_setting_for_project ( asana_project [ "gid" ] , { "custom_field" : custom_field_id } ) asana_project_update = { "custom_fields" : { current_app . config [ "ASANA_PROJECTS_CUSTOM_FIELDS" ] [ AsanaCustomFieldLabels . LINEAR_URL ] : linear_project_url , current_app . config [ "ASANA_PROJECTS_CUSTOM_FIELDS" ] [ AsanaCustomFieldLabels . TEAM ] : current_app . config [ "ASANA_CUSTOM_FIELD_TEAM_ENUM_VALUES" ] [ team_name ] , } } current_app . logger . debug ( f"updating project {asana_project['name']}" ) self . client . projects . update_project ( asana_project [ "gid" ] , asana_project_update ) new_members = { "members" : current_app . config [ "ASANA_PORTFOLIO_USERS_IDS" ] , } asana_project = self . client . projects . add_members_for_project ( asana_project [ "gid" ] , new_members ) current_app . logger . info ( f"Asana project created: {asana_project['name']}" ) current_app . logger . debug ( f"re-fetching project: {asana_project['name']}" ) asana_project = self . client . projects . get_project ( asana_project [ "gid" ] ) current_app . logger . debug ( f"project fetched: {asana_project}" ) return asana_project
Create Asana project from linear project values
Create Asana project from linear project values
"""Create Asana project from linear project values""" # We can only add certain fields (ex: a custom field) to the project once it was added to the portfolio # add project to portfolio # Add custom fields for the project # For some reason portfolios in Asana doesn't display the teams values on projects. # Instead we have to use a custom field for the team # Add initial members to created project # fetch the project again with the latest fields
self
linear_project
LinearProject
squad_portfolio_gid
str