Skip to content

feat: generate samples - #2056

Merged
JustinBeckwith merged 5 commits into
masterfrom
samplegen
May 7, 2020
Merged

JustinBeckwith merged 5 commits into
masterfrom
samplegen

Conversation

@JustinBeckwith

@JustinBeckwith JustinBeckwith commented Apr 24, 2020 •

Copy link
Copy Markdown
Contributor

This PR removes the code that downloads sample snippets from GCS, and replaces it with an in-house generator. For reasons I don't fully understand, dartman was only generating samples for a small select number of APIs. It was easy enough to make this generic, so I rolled it out broadly.

The interesting files are at the bottom of the list, so scroll down

TODO:

  • Generate one sample per API method in standalone files
  • Get look-behind regex working for projects/my-project paths

After this lands:

  • Update whatever tool cloudsite uses to inline current GCS / disco-artifact-generator samples
  • Delete code in disco-artifact manager that produces nodejs samples

Stuff to think about:

  • I dropped the generation of pagination code. If we care that much, I'll add a pagination feature.
  • The plan is to eventually generate standalone samples as well to replace the dartman generated ones used on cloudsite. All the bits are here, lets just save it for a followup PR.

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Apr 24, 2020
@JustinBeckwith JustinBeckwith added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Apr 24, 2020
Comment thread src/generator/generator.ts Resolved
Comment thread src/generator/generator.ts Resolved
Comment thread src/generator/templates/sample.njk Resolved
Comment thread src/generator/templates/sample.njk Resolved
Comment thread src/generator/templates/sample.njk Resolved
@JustinBeckwith
JustinBeckwith force-pushed the samplegen branch 4 times, most recently from 9aa342d to 4b4c7f4 Compare May 1, 2020 20:27
@codecov

codecov Bot commented May 1, 2020 •

Copy link
Copy Markdown

Codecov Report

Merging #2056 into master will increase coverage by 6.24%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2056      +/-   ##
==========================================
+ Coverage   43.64%   49.88%   +6.24%     
==========================================
  Files           7        9       +2     
  Lines        1219     1333     +114     
  Branches       22       21       -1     
==========================================
+ Hits          532      665     +133     
+ Misses        687      668      -19     
Impacted Files Coverage Δ
src/generator/filters.ts 34.11% <ø> (ø)
src/generator/generator.ts 0.00% <ø> (ø)
src/generator/samplegen.ts 86.04% <ø> (ø)
src/generator/download.ts 55.08% <0.00%> (-43.23%) ⬇️
src/googleapis.ts 74.46% <0.00%> (-15.61%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9d612d7...4858cd6. Read the comment docs.

@JustinBeckwith
JustinBeckwith force-pushed the samplegen branch 3 times, most recently from b03ab86 to daf1eb1 Compare May 5, 2020 03:42
@bcoe

bcoe commented May 6, 2020

Copy link
Copy Markdown

I dropped the generation of pagination code. If we care that much, I'll add a pagination feature.

I wonder if we could show an async iterator in action, they simplify pagination a ton.

@JustinBeckwith JustinBeckwith removed the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label May 7, 2020
@JustinBeckwith

Copy link
Copy Markdown
Contributor Author

@alexander-fenster @bcoe this is ready for a look for real

Comment thread src/apis/abusiveexperiencereport/v1.ts Resolved
* // Do the magic
* const res = await abusiveexperiencereport.sites.get({
* // Required. The name of the site whose summary to get, e.g.
* // `sites/http%3A%2F%2Fwww.google.com%2F`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to be like this, or do we need | safe? (I really don't know)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I do use | safe. Turns out this is exactly what's in the source discovery doc 🤦

Comment thread src/generator/filters.ts Resolved
Comment thread src/generator/filters.ts Resolved
Comment thread src/generator/generator.ts Resolved
@JustinBeckwith

Copy link
Copy Markdown
Contributor Author

@bcoe I'm entirely open to adding the pagination stuff with async iterators. As a first step, we need to hand craft a sample with tests and such. Any concerns with punting that to a followup PR?

@bcoe bcoe left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking great to me.

One small concern, to address user issues with samples, will we now need to fix the issue both in discovery-artifact-manager and here. I would love for this to be the source of truth for Node.js apiary samples.

*
* // Acquire an auth client, and bind it to all future calls
* const authClient = await auth.getClient();
* google.options('auth', authClient);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that there are now inline examples, we should double check that our refdoc generator renders these appropriately at deploy time.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fun fact: inline samples are generally broken in compodoc 😭
compodoc/compodoc#304

The inline example is no more broken than it was before I guess? I think @fhinkel is working on a plan to save us

{% if standalone %}
{% include "license.njk" %}

// THIS FILE IS AUTO-GENERATED

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what generates this file?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hah, this is hand written - I want the files it generates to have that comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants