GithubHelp home page GithubHelp logo

pix4d / cogito Goto Github PK

View Code? Open in Web Editor NEW
34.0 23.0 14.0 1.1 MB

Concourse resource for GitHub Commit Status and Google Chat notifications

License: MIT License

Dockerfile 0.47% Go 98.82% Shell 0.71%
concourse concourse-resource cicd go github-status google-chat owner-platform-ci

cogito's People

Contributors

aledegano avatar aliculpix4d avatar esysc avatar iamoric avatar lsjostro avatar marco-m avatar marco-m-pix4d avatar muzaffar-omer avatar odormond avatar tgolsson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cogito's Issues

Support for Enterprise Github?

Does this line mean that for Enterprise Github (not github.com) will now work?

left := []string{"github.com", owner, repo}

fetching pix4d/cogito@sha256:cef4adfe17e9ee5f7c16a4094e435d88857f663f080507dcb6b61e7390b52852
29291e31a76a [==========================================] 2.7MiB/2.7MiB
ff9cc595764e [======================================] 274.7KiB/274.7KiB
60eff1c2ce14 [==============================================] 116b/116b
507e2309724c [==========================================] 5.9MiB/5.9MiB
This is the Cogito GitHub status resource. Tag: 0.6.0, commit: 5d34381a18, build date: 2021-08-26
resource source configuration and git repository are incompatible.
Git remote: "https://notgithub.com/xxx/xxx.git"
Resource config: host: github.com, owner: "xxx", repo: "xxx". wrong git remote

report commit author and message

Currently we send to the chat sink:

2023-07-24 09:04:37 UTC
pipeline foo-bar
job oo-bar-local-tests/1301
state ๐Ÿ”ด failure
commit 123456 (repo: example/repo)

It would be nice to send also the commit author and message (no matter the state):

2023-07-24 09:04:37 UTC
pipeline foo-bar
job oo-bar-local-tests/1301
state ๐Ÿ”ด failure
commit 123456 (repo: example/repo)

Same for the logging.

What we have:

[INFO]  cogito: This is the Cogito GitHub status resource. Tag: 0.10.1, commit: 05c92db, build date: 2023-05-31
[INFO]  cogito.put.ghCommitStatus: GitHub HTTP request: attempt=1 max=3
[INFO]  cogito.put.ghCommitStatus: commit status posted successfully: state=pending git-ref=123456

What we could have

[INFO]  cogito: This is the Cogito GitHub status resource. Tag: 0.10.1, commit: 05c92db, build date: 2023-05-31
[INFO]  cogito.put.ghCommitStatus: Processing commit git-ref=123456 author=johnny.stecchino comment="foo: add bar"
[INFO]  cogito.put.ghCommitStatus: GitHub HTTP request: attempt=1 max=3
[INFO]  cogito.put.ghCommitStatus: commit status posted successfully: state=pending git-ref=123456

retry GitHub HTTP request when rate limited: does not sleep when it should

We detect the situation correctly, we calculate the correct time to sleep, we log that we will sleep but actually we do NOT sleep, thus we consume the 3 attempts one after the other and finally fail:

[INFO]  cogito: This is the Cogito GitHub status resource. Tag: 0.10.2, commit: d8221ad, build date: 2023-07-28
[INFO]  cogito.put.gChat: not sending to chat: reason="feature not enabled"
[INFO]  cogito.put.ghCommitStatus: GitHub HTTP request: attempt=1 max=3
[INFO]  cogito.put.ghCommitStatus: Sleeping for: duration=7m42s reason="rate limited, should retry"
[INFO]  cogito.put.ghCommitStatus: GitHub HTTP request: attempt=2 max=3
[INFO]  cogito.put.ghCommitStatus: Sleeping for: duration=7m42s reason="rate limited, should retry"
[INFO]  cogito.put.ghCommitStatus: GitHub HTTP request: attempt=3 max=3
[INFO]  cogito.put.ghCommitStatus: Sleeping for: duration=7m42s reason="rate limited, should retry"

cogito: error: put: failed to add state "pending" for commit XXX: 403 Forbidden
Body: {"message":"API rate limit exceeded for user ID YYY.","documentation_url":"https://docs.github.com/rest/overview/resources-in-the-rest-api#rate-limiting"}
Hint: Rate limited but the wait time to reset would be longer than 15m0s (MaxSleepTime)

This has been introduced by #128

๐Ÿ˜ฟ

cogito: error: put: internal error: unexpected: negative sleep time: 0s

Just observed in our deployment:

[INFO]  cogito: This is the Cogito GitHub status resource. Tag: 0.10.1, commit: 05c92db, build date: 2023-05-31
[INFO]  cogito.put.ghCommitStatus: GitHub HTTP request: attempt=1 max=3
[INFO]  cogito.put.ghCommitStatus: Sleeping for: time=4m47s
[INFO]  cogito.put.ghCommitStatus: GitHub HTTP request: attempt=2 max=3
cogito: error: put: internal error: unexpected: negative sleep time: 0s

See also #123.

Provide a way to override BUILD_JOB_NAME === context on resources.

Right now the resource requires that you put all tasks that affect the same job status together in the same job within a pipeline because of the choice to make github "context" === BUILD_JOB_NAME. For reference, I believe this is where we set it. https://github.com/Pix4D/cogito/blob/master/resource/resource.go#L213-L215

I'd like to propose allowing users to pass in an optional parameter "context" that overrides the job name as the CONTEXT arg if not equal to "". Any objections or "gotchas" you can think of? Any reason you'd rather not have this property be configurable?

I'm happy to PR this if you think the feature has a chance.

FEATURE REQUEST: Dry-run flag

Dear Cogito maintainers,
Any chance you'd add a dry run configuration to your pipeline? The idea there is if a pipeline fails rather than alerting as it would do in the staging env, the pipeline step might no-op and alert the user that no request had gone out. We'd love such a feature for our staging concourse environment. I'd PR if you're open to it, or accept suggested implementations if there's something I'm not seeing in your readme.
Thanks!
Eli

Build links for instanced pipelines don't work

We use Instanced Pipelines, and the build links we get for them in GitHub don't appear to work. Here is an example of a link from cogito:

https://concourse/teams/teamname/pipelines/pipeline_name/jobs/job_name/builds/5?vars=%7B%22DEPLOYMENTID%22%3A%222%22%2C%22DESC%22%3A%22Daily+tests+for+Preprod+2%22%2C%22TITLE%22%3A%22PREPROD+TESTS%22%7D

an example of a working link for the above build

https://concourse/teams/teamname/pipelines/pipeline_name/jobs/job_name/builds/5?vars.DEPLOYMENTID=%222%22&vars.DESC=%22Daily%20tests%20for%20Preprod%202%22&vars.TITLE=%22PREPROD%20TESTS%22

When retrying an HTTP request to GitHub, Cogito does not print why

With the default log level, in case of retry, Cogito prints:

[INFO]  cogito.put.ghCommitStatus: GitHub HTTP request: attempt=1 max=3
[INFO]  cogito.put.ghCommitStatus: Sleeping for: time=4m47s

At line 2, the user can infer that the attempt at line 1 failed, but the reason (the HTTP status code) is not printed.
Instead, we should print the reason, because it would make easier to troubleshoot if needed.

Support custom user configuration in integration tests

Hello,

As I was going through CONTRIBUTING.md to run the integration tests, and I modified the tasks.yml to input my own values from gopass into task test:env -- task test:all. I was wondering if it would be possible to open a PR to merge these changes.

Ex:

+++ b/Taskfile.yml
@@ -48,13 +48,16 @@ tasks:
     cmds:
       - '{{ .CLI_ARGS }}'
     env: &test-env
-      COGITO_TEST_COMMIT_SHA: '{{default "32e4b4f91bb8de500f6a7aa2011f93c3f322381c" .COGITO_TEST_COMMIT_SHA}}'
+      COGITO_TEST_COMMIT_SHA: 
+        sh: 'echo -n {{default "$(gopass show cogito/test_commit_sha)" .COGITO_TEST_COMMIT_SHA}}'
       COGITO_TEST_OAUTH_TOKEN:
-        sh: 'echo {{default "$(gopass show cogito/test_oauth_token)" .COGITO_TEST_OAUTH_TOKEN}}'
-      COGITO_TEST_REPO_NAME: '{{default "cogito-test-read-write" .COGITO_TEST_REPO_NAME}}'
-      COGITO_TEST_REPO_OWNER: '{{default "pix4d" .COGITO_TEST_REPO_OWNER}}'
+        sh: 'echo -n {{default "$(gopass show cogito/test_oauth_token)" .COGITO_TEST_OAUTH_TOKEN}}'
+      COGITO_TEST_REPO_NAME: 
+        sh: 'echo -n {{default "$(gopass show cogito/test_repo_name)" .COGITO_TEST_REPO_NAME}}'
+      COGITO_TEST_REPO_OWNER: 
+        sh: 'echo -n {{default "$(gopass show cogito/test_repo_owner)" .COGITO_TEST_REPO_OWNER}}'
       COGITO_TEST_GCHAT_HOOK:
-        sh: 'echo {{default "$(gopass show cogito/test_gchat_webhook)" .COGITO_TEST_GCHAT_HOOK}}'
+        sh: 'echo -n {{default "$(gopass show cogito/test_gchat_webhook)" .COGITO_TEST_GCHAT_HOOK}}'

--- a/github/commitstatus_test.go
+++ b/github/commitstatus_test.go
@@ -168,34 +168,34 @@ func TestGitHubStatusFailureIntegration(t *testing.T) {
                {
                        name:  "bad token: Unauthorized",
                        token: "bad-token",
-                       wantErr: `failed to add state "success" for commit 32e4b4f: 401 Unauthorized
+                       wantErr: fmt.Sprintf(`failed to add state "success" for commit %s: 401 Unauthorized
 Body: {"message":"Bad credentials","documentation_url":"https://docs.github.com/rest"}
 Hint: Either wrong credentials or PAT expired (check your email for expiration notice)
-Action: POST https://api.github.com/repos/pix4d/cogito-test-read-write/statuses/32e4b4f91bb8de500f6a7aa2011f93c3f322381c
-OAuth: X-Accepted-Oauth-Scopes: [], X-Oauth-Scopes: []`,
+Action: POST https://api.github.com/repos/%s/%s/statuses/%s
+OAuth: X-Accepted-Oauth-Scopes: [], X-Oauth-Scopes: []`, cfg.SHA[0:7], cfg.Owner, cfg.Repo, cfg.SHA),```

(If this was already possible to do, but I ran the commands incorrectly, please let me know, thanks!)

Add pipeline name as prefix to context

I'm trying out concourse and setting up for a monorepo/multi-project workflow, and it's easy to end up having test/validate/build jobs in multiple pipelines for the same repository, etc. I'm wondering what your stance is on prefixing the pipeline name to the context, if the information is available? As an example, instead of just test for the test job it'd be for example publish-docker-image/test if this test is part of the publishing pipeline.

What json data should be passed onto STDIN when testing /opt/resource/out?

Apologies in advance if this is not the right place to ask questions, but I know no other options.

Within the cogito image, I'm trying to run the /opt/resource/out command by passing on a json data manually through STDIN for PUT. What is the exact format of the data that is required? I keep encountering some argument error from the json data. The task file looks like so:

---
platform: linux
image_resource:
  type: registry-image
  source:
    repository: ((redacted))/cogito-gh-status-resource
    tag: ((redacted))
    username: ((redacted))
    password: ((redacted))
inputs:
  - name: git-source
run:
  path: sh
  args:
    - -exc
    - |
      /opt/resource/out . < git-source/instana-tasks-resource/ci/request-data/request-data-populated.json

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.