Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Notify commit owner via slack message (#37803)
## What Updates our slack lifecycle notifications to mention the author of the metadata change on slack ![image.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/PTsI7qAmiIMkhFQg04QF/b20cd2d2-dc18-4a15-ae0e-0f8a218cf871.png) Spun out of #32715 as a stack
- Loading branch information
Showing
8 changed files
with
188 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
airbyte-ci/connectors/metadata_service/orchestrator/orchestrator/assets/slack.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# | ||
# Copyright (c) 2023 Airbyte, Inc., all rights reserved. | ||
# | ||
|
||
import os | ||
|
||
import pandas as pd | ||
from dagster import AutoMaterializePolicy, FreshnessPolicy, OpExecutionContext, Output, asset | ||
from orchestrator.utils.dagster_helpers import OutputDataFrame, output_dataframe | ||
|
||
GROUP_NAME = "slack" | ||
|
||
USER_REQUEST_CHUNK_SIZE = 2000 | ||
MAX_REQUESTS = 5 | ||
|
||
|
||
@asset( | ||
group_name=GROUP_NAME, | ||
required_resource_keys={"slack"}, | ||
auto_materialize_policy=AutoMaterializePolicy.eager(), | ||
freshness_policy=FreshnessPolicy(maximum_lag_minutes=60 * 12), | ||
) | ||
def airbyte_slack_users(context: OpExecutionContext) -> OutputDataFrame: | ||
""" | ||
Return a list of all users in the airbyte slack. | ||
""" | ||
if not os.getenv("SLACK_TOKEN"): | ||
context.log.info("Skipping Slack Users asset as SLACK_TOKEN is not set") | ||
return None | ||
|
||
client = context.resources.slack.get_client() | ||
users_response = client.users_list(limit=2000) | ||
metadata = users_response.data["response_metadata"] | ||
users = users_response.data["members"] | ||
requests_count = 1 | ||
|
||
while metadata["next_cursor"] and requests_count < MAX_REQUESTS: | ||
users_response = client.users_list(limit=2000, cursor=metadata["next_cursor"]) | ||
metadata = users_response.data["response_metadata"] | ||
users.extend(users_response.data["members"]) | ||
requests_count += 1 | ||
|
||
# Convert to a dataframe of id, real_name, and email | ||
# Remove any deleted or bot profiles | ||
users_df = pd.DataFrame(users) | ||
users_df = users_df[users_df["deleted"] == False] | ||
users_df = users_df[users_df["is_bot"] == False] | ||
users_df["email"] = users_df["profile"].apply(lambda x: x.get("email", None)) | ||
users_df = users_df[["id", "real_name", "email"]] | ||
|
||
return output_dataframe(users_df) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
airbyte-ci/connectors/metadata_service/orchestrator/orchestrator/utils/blob_helpers.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Copyright (c) 2023 Airbyte, Inc., all rights reserved. | ||
|
||
import yaml | ||
from google.cloud import storage | ||
|
||
|
||
def yaml_blob_to_dict(yaml_blob: storage.Blob) -> dict: | ||
""" | ||
Convert the given yaml blob to a dictionary. | ||
""" | ||
yaml_string = yaml_blob.download_as_string().decode("utf-8") | ||
return yaml.safe_load(yaml_string) |
8 changes: 4 additions & 4 deletions
8
airbyte-ci/connectors/metadata_service/orchestrator/poetry.lock
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters