diff --git a/.github/workflows/daily-push-to-google.yml b/.github/workflows/daily-push-to-google.yml new file mode 100644 index 0000000..e33b134 --- /dev/null +++ b/.github/workflows/daily-push-to-google.yml @@ -0,0 +1,27 @@ +name: Daily Push To Google from Jira + +on: + schedule: + - cron: '0 */8 * * *' # this will run three times a day (every 8 hours) + workflow_dispatch: # this allows the workflow to be run manually from the Actions tab + +jobs: + run-container-and-send-email: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup Google Credentials + run: | + echo "${{ secrets.GOOGLE_SERVICE_ACCOUNT_CREDENTIALS }}" > gcp_creds.json + + - name: Run Docker Container + run: | + ls -la && cat ./gcp_creds.json && + docker run --rm -v $(pwd)/gcp_creds.json:/tmp/gcp_creds.json \ + -e GOOGLE_SERVICE_ACCOUNT_CREDENTIALS=/tmp/gcp_creds.json \ + -e JIRA_TOKEN=${{ secrets.JIRA_TOKEN }} \ + -e GOOGLE_SHEETS_TOKEN=${{ secrets.GOOGLE_SHEETS_TOKEN }} \ + riscvintl/jira-to-google:latest diff --git a/from-jira-to-google.py b/from-jira-to-google.py index e761275..45dc93f 100644 --- a/from-jira-to-google.py +++ b/from-jira-to-google.py @@ -138,38 +138,38 @@ def get_quarter_year_format(date): return f"Q{quarter}-{year}" -# def get_credentials(): -# """ -# Function to get Google API credentials from the service account file. -# Returns the credentials object. -# """ -# creds = Credentials.from_service_account_file('token.json') - -# # If modifying the scopes, delete the token.json file -# SCOPES = ['https://www.googleapis.com/auth/spreadsheets', -# 'https://www.googleapis.com/auth/drive'] -# scoped_creds = creds.with_scopes(SCOPES) - -# return scoped_creds - - def get_credentials(): """ - Function to get Google API credentials from the environment variable. + Function to get Google API credentials from the service account file. Returns the credentials object. """ - creds_info = os.getenv('GOOGLE_SERVICE_ACCOUNT_CREDENTIALS') - creds_json = json.loads(creds_info) - creds = service_account.Credentials.from_service_account_info(creds_json) + creds = Credentials.from_service_account_file('gcp_creds.json') # If modifying the scopes, delete the token.json file - SCOPES = ['https://www.googleapis.com/auth/spreadsheets', + SCOPES = ['https://www.googleapis.com/auth/spreadsheets', 'https://www.googleapis.com/auth/drive'] scoped_creds = creds.with_scopes(SCOPES) return scoped_creds +# def get_credentials(): +# """ +# Function to get Google API credentials from the environment variable. +# Returns the credentials object. +# """ +# creds_info = os.getenv('GOOGLE_SERVICE_ACCOUNT_CREDENTIALS') +# creds_json = json.loads(creds_info) +# creds = service_account.Credentials.from_service_account_info(creds_json) + +# # If modifying the scopes, delete the token.json file +# SCOPES = ['https://www.googleapis.com/auth/spreadsheets', +# 'https://www.googleapis.com/auth/drive'] +# scoped_creds = creds.with_scopes(SCOPES) + +# return scoped_creds + + def read_csv_file(file_path): """ Function to read a CSV file and return its content as a list of rows.